PDA

View Full Version : Getting no output from this code, should be a square! Help please



panther
09-07-2014, 01:01 AM
#include<GL\glut.h>
#include<GL/math_3d.h>

void RenderScene()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);



glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glColor3f(0.0,0.0,1.0);

glBegin(GL_QUADS);

glVertex3f(1.0f,1.0f,0.0f);
glVertex3f(1.0f,3.0f,0.0f);
glVertex3f(3.0f,1.0f,0.0f);
glVertex3f(3.0f,3.0f,0.0f);

glEnd();

glutSwapBuffers();
}

int main(int argc, char *argv[])
{

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);

glutInitWindowSize(1024,768);
glutInitWindowPosition(0,0);
glutCreateWindow("Test");




glutDisplayFunc(RenderScene);
glutMainLoop();



}

Dan Bartlett
09-07-2014, 01:51 AM
Your quad is off the edge of the screen, try drawing closer to the origin, eg. (0,0,0) - (1,1,0) rather than (1,1,0) - (3,3,0).

panther
09-07-2014, 02:51 AM
I have to draw multiple shapes on the screen, adjusting them between (0,0) and (1,1) is not possible, is there any way past it?

carsten neumann
09-07-2014, 06:15 AM
There is, you can use the modelview matrix to place objects and your camera in the scene and the projection matrix to specify how things get mapped into screen space. Take a look at the list of tutorials at wiki (http://www.opengl.org/wiki/Getting_Started#Tutorials_and_How_To_Guides) - the ones from the pre-OpenGL 3.0 section are the ones that deal with how these things work when using the built in matrices and glBegin()/glEnd() style drawing.

Yandersen
09-07-2014, 08:50 AM
Aside from that, change the primitive type to GL_TRIANGLE_STRIP or inverse the order of first two vertices.