Question

#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();}

This program should just create one orange line in 3D but it seems to give me a black screen every time. I made sure to swap buffers because I am using a double buffer and I redisplay everytime it runs through vertex.. Not sure what is wrong

Was it helpful?

Solution

You are drawing outside of the view frustum. glOrtho defines a frustum which is limited in the z dimension in [-near,-far] (note the negative sign).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top