我想實作一個資料驅動的一個程式,資料準備好了后,交給OpenGL繪制。但是發現OpenGL并不能繪制成功,也就是opengl不能接收其他執行緒給與的資料,甚至我執行緒呼叫opengl也無法實作,希望各位前輩給與指導。代碼如下:
private void draw(){
GL.Begin(BeginMode.LineStrip);
GL.Vertex2(10,r.Next(200));
GL.Vertex2(30,r.Next(200));
GL.Vertex2(40,r.Next(200));
GL.Vertex2(50,r.Next(200));
GL.End()
GL.Flush();
glControl1.SwapBuffers();
glControl1.Invalidate();
}
private void button1_Click(object sender,EventArgs e){
Thread t=new Thread(draw);
t.start();
}
結果并不能進行繪制圖象,請賜教如何才能達到我想要的功能?
我之前的程式用GDI+實作了一種繪制圖形的模式:
public void dispatchTask(){
while(true){
int[] datas=getData();
UI.BeginInvoke(datas); //異步UI繪制
FIO.BeginInvoke(datas);//異步輸出到檔案
Thread.sleep(200);
}
}
現在的UI想換成OpenGL實作,但是出現了問題,請教大家
uj5u.com熱心網友回復:
opengl的繪制只能在主執行緒進行吧,你可以把資料處理、訊息處理等放在別的執行緒轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/71090.html
標籤:其它游戲引擎
上一篇:unity中的滑鼠事件
下一篇:沒有人在中國喜歡D3D12?
