I’m developing C++ OpenGL code in Windows using Visual Studio 2008. I can’t for the life of me understand why none of the integer functions work. I’ll try using glVertex2i(2,2) but all I get is a black screen, I’ve also tried this with glrecti but I have had the same result.
When I use the floating point functions, they work. glVertex2f(.5,.5) and glRectf(1,2,3,4) work fine. I just can’t figure out what is going wrong, what I have missed. People have obviously used glVertex2i before and had it work.
The simple code I’ve been working off of is this:
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
void draw(){
glClearColor(0,0,0,1);
glClear( GL_COLOR_BUFFER_BIT );
glColor3f(1, 1, 1);
glBegin(GL_LINES);
glVertex2i(100,100);
glVertex2i(200,200);
glEnd();
glFlush();
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitWindowSize(600, 600);
glutCreateWindow("My first OpenGL program");
glutDisplayFunc(draw);
glutMainLoop();
}
Your code doesn’t set any projection matrices, so passing values outside [-1, 1] is drawing outside of the viewport. That’s why integer functions “don’t work”.