2014-03-28 87 views
0
#include <GL/freeglut.h> 
#include <stdlib.h> 
void vertex() 
{ 
glLineWidth(5.0); 
glBegin(GL_LINES); 
{ 
glColor3f(1,0.5,0.0);//colour added 
glVertex3f(0.0,0.0,0.0); 
glVertex3f(0.0,5.0,9.0); 
} 
glEnd(); 
glutPostRedisplay(); 
} 
void myDisplay(void) 
{ 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
glLoadIdentity();//load the identity matrix 
vertex(); 
glutSwapBuffers(); 
} 
void initializeGL(void) 
{ 
glFlush();//initialize the screen before adding any elements 
glEnable(GL_DEPTH_TEST); 
glEnable (GL_BLEND); 
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
glClearColor(0,0,0,1.0); 
glMatrixMode(GL_PROJECTION); 
glLoadIdentity(); 
glOrtho(-70.0,70.0,-70.0,70.0,0.01,80.0);//set the max mins for x,y and z 
glMatrixMode(GL_MODELVIEW); 
} 
int main(int argc, char** argv) 
{ 
glutInit(&argc,argv); 
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); 
glutInitWindowSize(500,500); 
glutInitWindowPosition(100,150); 
glutCreateWindow("3D line"); 
glutDisplayFunc(myDisplay); 
glEnable(GL_DEPTH_TEST); 
initializeGL(); 
glutMainLoop();} 

該程序應該只是在3D中創建一條橙色線條,但它似乎每次都會給我一個黑色的屏幕。我確保交換緩衝區,因爲我使用的是雙緩衝區,並且每當它運行通過頂點時我都會重新顯示。不知道什麼是錯的Open GL在簡單的3D線上顯示空白窗口

回答

0

您正在繪製視錐之外。 glOrtho定義了一個平截頭體,它在[-near,-far]的z維上有限制(注意負號)。