PDA

View Full Version : problem with starting program (GLUT)



rom
07-11-2000, 04:08 AM
The following program doesn't draw pixels on a window but only a black window. Is there a problem with my OpenGL librairies or a bug in the program ?

#incude <gl/glut.h>
#include <gl/gl.h>
#include <gl/glu.h>


void init(void)
{
};

void idle(void)
{
glutPostRedisplay();
};

void Reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);

}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(1.0,0.0,0.0);
glBegin(GL_POINTS);
glVertex2i(0.0,0.0);
glVertex2i(0.0,3.0);
glVertex2i(3.0,3.0);
glVertex2i(4.0,4.5);
glVertex2i(3.0,0.0);
glEnd();
glutSwapBuffers();
glutPostRedisplay();
};

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize (640, 480);
glutInitWindowPosition (10, 10);
glutCreateWindow ("Polygon 5 vertex s");
init ();
glutDisplayFunc(display);
glutReshapeFunc(Reshape);
glutIdleFunc(idle);
glutMainLoop();
return 0;
};

Relic
07-11-2000, 05:00 AM
All your points are on z=0, but your viewing frustum starts at 1.5.
Move things to lie in the middle of the viewing frustum for example:
void Reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glTranslatef(0.0f, 0.0f, -10.75f);
glMatrixMode (GL_MODELVIEW);
}
BTW, don't send doubles to glVertex2i, 4.5 won't work as expected.



[This message has been edited by Relic (edited 07-11-2000).]

rom
07-11-2000, 11:24 AM
First, thank you Elric for your answer.
I have changed my program as said, as well as the vertex2i (put integer) but I have always the same result. gluLookAt has been tried but always a black windows without a pixel.
I use VC++ 5.0 (Nobody is perfect !!)

#include <gl/glut.h>
#include <gl/gl.h>
#include <gl/glu.h>


void init(void)
{

};

void idle(void)
{
glutPostRedisplay();
};


void Reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glTranslatef(0.0f, 0.0f, -10.75f);
glMatrixMode (GL_MODELVIEW);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glColor3f(0.0,0.0,0.0);
//gluLookAt(0,0,-10,0,0,0,0,1,0);
glBegin(GL_TRIANGLES);
glVertex2i(0,1);
glVertex2i(-1,0);
glVertex2i(1,0);
glEnd();

glutSwapBuffers();
glutPostRedisplay();
};


int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize (640, 480);
glutInitWindowPosition (10, 10);
glutCreateWindow ("Polygon 5 vertex s");
init ();
glutDisplayFunc(display);
glutReshapeFunc(Reshape);
glutIdleFunc(idle);
glutMainLoop();
return 0;
};

07-11-2000, 03:30 PM
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); ?

07-11-2000, 03:31 PM
try glVertex3i(X, Y, -4)

07-11-2000, 03:35 PM
drrr... you have the vertexes color set to black........ change them to some other color or set the background a different color

ignore the last two posts

rom
07-12-2000, 06:09 AM
thank you for all
I have changed the program (put differant colors, changed the looking at...) but the problem is always the same : a black window without a pixel.
I have also include *.lib (opengl32,glut & glu32) but it doesn't work.
#include <gl/glut.h>
#include <gl/gl.h>
#include <gl/glu.h>

void init(void)
{
};

void idle(void)
{
glutPostRedisplay();
};
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
gluLookAt(3,2,3,0,0,0,0,1,0);
glBegin(GL_POINTS);
glColor3d(1,0,1);
glVertex3i(0,0,0);
glColor3d(1,1,1);
glVertex3i(0,1,0);
glColor3d(1,0,1);
glVertex3i(0,0,-4);
glColor3d(1,0,0);
glVertex3i(1,0,-4);
glColor3d(1,1,1);
glVertex3i(0,0,-4);
glColor3d(1,1,1);
glVertex3i(0,0,1);
glEnd();
glutSwapBuffers();
glutPostRedisplay();
};


void ReshapeFunc(int w, int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); gluPerspective(45,float(w)/float(h),0,100);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize (640, 480);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Polygon 5 vertex s");
init ();
glutDisplayFunc(display);
glutReshapeFunc(ReshapeFunc);
glutMainLoop();
return 0;
};

Relic
07-12-2000, 06:31 AM
Some tips on how to get programs debugged:
- Don't change multiple things at once, before you got the first version running.
- Have a look at the GLUT library samples like the redbook's double.c or smooth.c. Those draw a white quad resp. a gouraud shaded triangle and they definitely work.
- And read the OpenGL Programming Guide!

The gluPerspective must not contain zNear=0.
Leave the gluLookAt away until you have understood how the projection works.
gluLookAt postmultiplies the current matrix, but you haven't set the identity back and you're animating, so this moves somewhere.


[This message has been edited by Relic (edited 07-12-2000).]

rom
07-12-2000, 06:39 AM
thanks RELIC

Noah
07-12-2000, 09:42 PM
Try translating or rotationg your scene to see if you can find the objects, if you can't find anything, then something else is wrong, if you find them eventually, then your perspective is just wrong.

-Noah Desch

Tone
07-12-2000, 11:27 PM
Maybe I'm missing something here, but does it make sense to call glutPostRedisplay() at the end of your display() function? I only use it when I am animating something. Near as I can tell, your program creates a static scene. Also, I think it would be a good idea to call glFlush() at the end of Display() to make sure that all your calls are executed by the pipeline. Hope this helps.

Tone

Relic
07-13-2000, 02:37 AM
SwapBuffers has an implicit glFinish included, so no need for the glFlush in this case.
Though, you'll have to add the glFlush or glFinish for single buffered apps.