I’m trying to just gain simple experience with openGL after reverse engineering a snake program using GLUT. I’m essentially using the same main body as the author of the code I’m using, however it does not behave as I would expect…
If anyone could enlighten me on what I’m doing wrong, I’d appreciate it (also any good openGL tutorials to check out for absolute beginnings with the API, I’m not completely new to C++ [~2 years experience with it]).
You are not giving the correct coordinates. That is x1, y1, x2, y2 values should be atleast enough to render a rectangle. You are giving it 250, 350, 250, 350 that means that your x1=x2 and y1=y2 which as far as I can see would not render anything. Instead give it 250, 250, 260, 360 which should render a 10x10 rectangle.
You winding order in the drawSquare function is wrong. Remember to give coordinates in an anticlockwise order like this assuming that x1<x2 and y1<y2
void drawSquare(int x1, int y1, int x2, int y2) {
glColor3f(0, 1, 0);
glBegin(GL_QUADS);
glVertex2f(x1, y1);
glVertex2f(x1, y2);
glVertex2f(x2, y2);
glVertex2f(x2, y1);
glEnd();
}
You are not giving the correct coordinates. That is x1, y1, x2, y2 values should be atleast enough to render a rectangle. You are giving it 250, 350, 250, 350 that means that your x1=x2 and y1=y2 which as far as I can see would not render anything. Instead give it 250, 250, 260, 360 which should render a 10x10 rectangle.
You winding order in the drawSquare function is wrong. Remember to give coordinates in an anticlockwise order like this assuming that x1<x2 and y1<y2
void drawSquare(int x1, int y1, int x2, int y2) {
glColor3f(0, 1, 0);
glBegin(GL_QUADS);
glVertex2f(x1, y1);
glVertex2f(x1, y2);
glVertex2f(x2, y2);
glVertex2f(x2, y1);
glEnd();
}
See if this helps.[/QUOTE]
Yup, that did the trick… Didn’t realize I was messing it up like that. Makes more sense now. Thanks!