PDA

View Full Version : Basic Glut Help



monkfish
08-06-2005, 07:56 AM
Hello,

I'm trying to teach myself basics of glut just now for some work i need to do and am having trouble with the viewing of my scene. The viewing plane has to be at z=-100, and from what I can tell I should be able to see the quad in the scene, but am unable too! I've tried a few alternatives but am having no luck, I'm sure that I'm just overlooking something simple! So any help on this would be great!

Thanks,




#include<GL/glut.h>
#include<GL/Gl.h>
#include<GL/Glu.h>


int Height=480;
int Width=640;

void myInit()
{
/* Set colour of window*/
glClearColor (1,1,1,1);

/* Set colour of lines)*/
glColor3f(1.0,1.0,0);



glViewport(0,0,Width,Height);
/* Manipulation of matrices to produce image */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(-Width/2, Width/2, -Height/2, Height/2, 0, -100);
}

void myDisplay()
{

glBegin(GL_QUADS); //tells OpenGL that we're going to start drawing triangles
glColor3f(1,0,0); //sets the current colour to red
glVertex3f(30,-20,-10);

glColor3f(0,1,0); //sets the current colour to green
glVertex3f(30,-20,-30);

glColor3f(0,0,1); //sets the current colour to blue
glVertex3f(-20,-20,-30);

glColor3f(0,0,1); //sets the current colour to blue
glVertex3f(-20,-20,-10);


glEnd();
glFlush();
}

void myReshape(int width, int height)
{
glViewport(0,0,Width,Height);
glMatrixMode(GL_PROJECTION); // set matrixMode to projection matrix
glLoadIdentity();
glOrtho(-Width/2, Width/2, -Height/2, Height/2, 0, -100);
glutPostRedisplay();
}

void main(int argc, char** argv)
{
/* GLUT initialisations */
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(Width, Height);
glutInitWindowPosition(100, 100);
glutCreateWindow("Gluttest");

glutReshapeFunc (myReshape);


/* Attach all the callbacks to the current window */
glutDisplayFunc(myDisplay);

/* Do some program specific initialisations */
myInit();

/* Enter the GLUT event loop */
glutMainLoop();
}

Dj3hut1
08-06-2005, 11:33 PM
Hello,

I think there are 3 reasons, why you can't see anything :

1. You forget to clear the colorbuffer at the beginning of your display function with glClear(GL_COLOR_BUFFER_BIT);

2. While defining the coords for your vertices you mixed up the y-axis and the z-axis, so your quad is perpendicular to the viewplane.

3. Even if the first two points where done right, you could't see your quad, because it is on "the wrong side". So either you take positive z coordinates or your far clip plane should have a positive value (glOrtho(-Width/2, Width/2, -Height/2, Height/2, 0, 100) instead of glOrtho(-Width/2, Width/2, -Height/2, Height/2, 0, -100);

monkfish
08-07-2005, 01:41 AM
Hello,

I think there are 3 reasons, why you can't see anything :

1. You forget to clear the colorbuffer at the beginning of your display function with glClear(GL_COLOR_BUFFER_BIT);

2. While defining the coords for your vertices you mixed up the y-axis and the z-axis, so your quad is perpendicular to the viewplane.

3. Even if the first two points where done right, you could't see your quad, because it is on "the wrong side". So either you take positive z coordinates or your far clip plane should have a positive value (glOrtho(-Width/2, Width/2, -Height/2, Height/2, 0, 100) instead of glOrtho(-Width/2, Width/2, -Height/2, Height/2, 0, -100); Thanks for your help. Unfortunately I'm still unable to see the objects.

I need the object to run perpendicular as it's meant to be a floor (which runs at y=-20), so it should be visible with orthographic projection? Although I have been having troubles with displaying this, does anyone know if theres a reason why?

With orthographic projection you also start by looking down the negative z axis, which is why the far viewing plane is set to -100.

Any more help on the matter would be much appreciated!

Dj3hut1
08-07-2005, 07:47 AM
oh, then i understand.
but it's not possible to make a floor visible in orthographic view mode. ;)
you should use perspective view mode (take gluPerspective instead of glOrtho)