PDA

View Full Version : my opengl program gives a blank output screen afte



prayas suneja
02-28-2011, 03:09 AM
i compiled this code and got no error.....but the output screen is blank.


the code is as follows:
-------------------------------------------------------------------------
# include <GL/glut.h>
# include <iostream>
# include <cstdio>
using namespace std;

void init(int w,int h)
{
glClearColor(0,0.5,0.5,0.0);
glMatrixMode(GL_PROJECTION);
glViewport(0,0,w,h);
}

void dispfcn()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2i(50,50);
glVertex2i(100,50);
glVertex2i(75,100);
glEnd();
glFlush();
}

int main(int argc,char**argv)
{
int w,h;
w=h=400;
glutInit(&amp;argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(w,h);
glutCreateWindow("triangle");
init(w,h);
glutDisplayFunc(dispfcn);
glutMainLoop();
return 0;
}
-------------------------------------------------------------------------

i compiled the program as follows:
g++ first.cpp -o first -lglut


it is a simple program to draw a triangle.....

i made this program with the help of some programs available on the internet(which worked perfectly fine in my distro) and the program i ran in visual c++(in my college lab),this is a hybrid...i guess there is some logical error or incorrect usage of function that's why blank screen is coming......
its working fine in the main where we can change the background display....but the 'dispfcn' is not displaying the triangle....

DarkGKnight
02-28-2011, 05:16 AM
You haven't specified any information about the projection matrix, e.g. no calls to gluPerspective, glFrustum or glOrtho. Also, you didn't specify any information for the modelview matrix, i.e. glMatrixMode(GL_MODELVIEW).