PDA

View Full Version : i cant display anything from this code. why?



nurulfaiz
12-13-2004, 08:05 PM
#include <GL/glut.h>

void init (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0); //Set display-window color //or can use glClearIndex (index);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (0.0, 200.0, 0.0, 150.0);
}

void lineSegment (void)
{
glClear (GL_COLOR_BUFFER_BIT);

glColor3f (0.0, 1.0, 0.0);

glBegin(GL_QUADS); // Draw A Quad

glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left

glEnd(); // Done Drawing The Quad

glFlush ();
}

void main (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (50, 100);
glutInitWindowSize (400, 300);
glutCreateWindow ("An example OpenGL Program");

init ();
glutDisplayFunc (lineSegment);
glutMainLoop ();
}

plasmonster
12-13-2004, 08:42 PM
There's nothing wrong with your code, per se, but you're going to need a microscope to see that tiny green quad in the lower left corner of your screen ;)

Try adjusting the parameters to gluOrtho2D, such that they're more in line with the size of your quad. It would do just as well to make your quad larger.