I am trying to draw a simple filled rectangle in OpenGL. All Google searching tells me that glRectf() should do this, by specifying the color beforehand with glColor4f(), however the rectangle is always drawn unfilled (borders only).
Is there anything I am missing, or need to specify in the code beforehand? Thanks!
答案 0 :(得分:1)
glRect() is a deprecated function in OpenGL 3.0, in later version they removed this function. be sure you have a compatibility profile.
printf("%s\n", glGetString(GL_VERSION));
if you want to know more read: https://www.opengl.org/wiki/Fixed_Function_Pipeline
if this is not the issue please test
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glColor3f(0.1, 0.2, 0.3);
glBegin(GL_QUADS);
glVertex2f(-1.0f, 1.0f);
glVertex2f(-1.0f, 0.0f);
glVertex2f(1.0f, 0.0f);
glVertex2f(1.0f, 1.0f);
glEnd();