我一直在尋找不同的OpenGL 3+代碼,只是爲了更熟悉。我也遵循教程並嘗試使用OpenGL進行編碼。有人可以爲我澄清此代碼
所以我找到了一個繪製球體的代碼。一些頂點下面發現,這裏是結果:
.
..
...
Sphere vertices are: >> Vertice 10281: X>0.000747, Y>-0.000275, Z>1.000000!
Sphere vertices are: >> Vertice 10282: X>0.000769, Y>-0.000208, Z>1.000000!
Sphere vertices are: >> Vertice 10283: X>0.084840, Y>-0.023011, Z>0.996129!
Sphere vertices are: >> Vertice 10284: X>0.084840, Y>-0.023011, Z>0.996129!
Sphere vertices are: >> Vertice 10285: X>0.000769, Y>-0.000208, Z>1.000000!
Sphere vertices are: >> Vertice 10286: X>0.000784, Y>-0.000141, Z>1.000000!
Sphere vertices are: >> Vertice 10287: X>0.086522, Y>-0.015533, Z>0.996129!
Sphere vertices are: >> Vertice 10288: X>0.086522, Y>-0.015533, Z>0.996129!
Sphere vertices are: >> Vertice 10289: X>0.000784, Y>-0.000141, Z>1.000000!
Sphere vertices are: >> Vertice 10290: X>0.000793, Y>-0.000072, Z>1.000000!
Sphere vertices are: >> Vertice 10291: X>0.087546, Y>-0.007936, Z>0.996129!
...
..
.
現在,我下載的代碼,繪製一個球在屏幕的中間。它使用glm包。我沒有得到的是,如何將「X = 0.087546」或「Z = 0.996129」轉換爲像素並繪製到屏幕軸上。
這裏是GLM代碼:
//PROJECTION
glm::mat4 Projection = glm::perspective(45.0f, 1.0f, 0.1f, 100.0f);
angle = (GLfloat) (i/50 % 360); //to dia gia nan pio argo
//printf("Angle: >>>> %f, \n", angle);
//VIEW
glm::mat4 View = glm::mat4(1.);
View = glm::translate(View, glm::vec3(0.f, 0.f, -5.0f)); // x, y, z position ?
//View = glm::rotate(View, angle * -1.0f, glm::vec3(1.f, 0.f, 0.f));
View = glm::rotate(View, angle * 0.5f, glm::vec3(0.f, 1.f, 0.f));
//View = glm::rotate(View, angle * 0.5f, glm::vec3(0.f, 0.f, 1.f));
//MODEL
glm::mat4 Model = glm::mat4(1.0);
glm::mat4 MVP = Projection * View * Model;
glUniformMatrix4fv(glGetUniformLocation(shaderprogram, "mvpmatrix"), 1, GL_FALSE, glm::value_ptr(MVP));
它正在產生的窗口是一個600個* 600像素的窗口。那麼X和Z如何映射到這些座標?
「那麼X和Z如何映射到這些座標?」你基本上在問,「頂點怎麼在OpenGL中渲染?」雖然我可以寫出這是如何工作的答案,[我已經做得更詳細了。](http://www.arcsynthesis.org/gltut/Basics/Intro%20Graphics%20and%20Rendering.html) –