2011-11-10 108 views

回答

2

如果您希望能夠直接在窗口空間中繪圖,那麼最簡單的方法是使用單位矩陣臨時加載模型視圖和投影,然後用您需要的位置繪製一個GL_POINT。所以這會是這樣的:

glMatrixMode(GL_MODELVIEW); 
glPushMatrix(); 
glLoadIdentity(); 

glMatrixMode(GL_PROJECTION); 
glPushMatrix(); 
glLoadIdentity(); 

// draw the point here; specifics depending on whether you 
// favour VBOs, VBAs, etc 

// e.g. (assuming you don't have any client state enabled 
// on entry and don't care about leaving the vertex array 
// enabled on exit) 
GLfloat vertexLocation[] = {0.0f, 0.0f, -1.0f}; 

glColor4f(0.0f, 0.0f, 0.0f, 1.0f); 
glEnableClientState(GL_VERTEX_ARRAY); 
glVertexPointer(3, GL_FLOAT, 0, vertexLocation); 

glDrawArrays(GL_POINTS, 0, 1); 

// end of example to plot a GL_POINT 

glPopMatrix(); 

glMatrixMode(GL_MODELVIEW); 
glPopMatrix(); 

// and possibly restore yourself to some other matrix mode 
// if, atypically, the rest of your code doesn't assume modelview 
+0

我不知道如何繪製點在0,0,-1,請你可以添加代碼嗎? – NullPointerException

+0

我已經添加了一些代碼,但重新閱讀您的問題,我想我可能誤解了您的問題。你想讓(0,0,-1)成爲你的3D世界中的位置嗎?如果你有一臺相機並移動了它,它會受到影響,還是你希望它直接在眼睛空間? – Tommy

+0

GLfloat不會在android上退出:S我應該使用什麼? – NullPointerException

相關問題