Reputation: 19
This code is supposed to just draw a circle on a window, but the circle doesn't show up. I'm using the function glVertex2f
.
#include <GLUT/glut.h>
#include <math.h>
void init(void) {
glClearColor(0.686, 0.933, 0.933,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,200.0,0.0,150.0);
}
void lineSegment(void) {
float theta;
int posX = 400;
int posY = 400;
int radio = 100;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,0.4,0.2);
glBegin(GL_POLYGON);
for(int i=0; i<360; i++){
theta = i*3.1416/180;
glVertex2f(posX + radio*cos(theta), posY + radio*sin(theta));
}
glEnd();
glFlush();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(50,50);
glutInitWindowSize(800,800);
glutCreateWindow("Cerámica Ana");
init();
glutDisplayFunc(lineSegment);
glutMainLoop();
}
Upvotes: 1
Views: 6986
Reputation: 211229
You have setup an orthographic projection:
gluOrtho2D(0.0,200.0,0.0,150.0);
The geometry within the rectangle, which is defined by the orthographic projection, is projected on the viewport. This means, that the geometry with coordinates form (0,0) to (200, 150) is visible on the viewport. The geometry out of this area is clipped.
But the center of the circle is at (500, 500) and is radius is 100. So it is not inside the clipping region.
Since the size of the viewport is (800, 800), I reommeend to adapt the orthgraphic projection to the viewport.
See gluOrtho2D
and glOrtho
.
Change the orthographic projection to solve the issue:
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 800.0, 0.0, 800.0);
Upvotes: 3