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(&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();
}