PDA

View Full Version : my first program not working



theju
03-06-2011, 07:08 AM
hi all,i hav been trying to draw a polygon without any succes please help the code is given below:
#include<stdio.h>
#include<GL/glut.H>

#include<conio.h>
void dis(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);


glBegin(GL_POLYGON);
glVertex2f(3.0,3.0);
glVertex2f(9.0,9.0);
glVertex2f(6.0,5.0);

glEnd();

glFlush();
}




void main(int argc,char**argv)
{
glutInit(&amp;argc,argv);
printf("hi");
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("hi");

glutDisplayFunc(dis);
glutMainLoop();


}

McLeary
03-06-2011, 07:55 AM
First, you need to set the type of projection you wanna use.

Take a look at http glOrtho (http://www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml).

Second, you need to load a model view matrix before any draw operations, something like:



glMatrixMode( GL_MODELVIEW );
glLoadIdentity();


If you're not comfortable with something, take a look at the Red Book (http://fly.cc.fer.hr/~unreal/theredbook/chapter01.html)