#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中创建一条橙色线,但它似乎每次都给我一个黑屏。我确保交换缓冲区,因为我使用双缓冲区,每次它通过顶点运行时重新显示..不确定是什么问题
答案 0 :(得分:0)
你正在视锥外面画画。 glOrtho
定义了[-near,-far]中z维度受限的平截头体(注意负号)。