我正在迈出进入 OpenGL 领域的第一步,但在Vertex声明方面遇到了麻烦。意思是,我只是通过使用窗口的相对大小作为坐标来成功定义顶点(那些 0.25 意味着 500*0.25=125)。这似乎不直观。
如何定义没有相对值的顶点?
#include <GLUT/glut.h>
#include <stdlib.h>
void displayInit(void) {
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
// Select a drawing color
glColor3f(1.0, 0.0, 0.0);
// Draw a square
glBegin(GL_POLYGON);
glVertex2f(-0.25, -0.25); // start from -1/4 window w, -1/4 window h
glVertex2f(-0.25, 0.25); // add point 1/4 window h up from center
glVertex2f(0.25, 0.25);
glVertex2f(0.25, -0.25);
glEnd();
// Display the whole drawing on screen
glFlush();
}
int main(int argc, char **argv) {
// Initialize with a window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
// Display first screen
displayInit();
// Enter the display loop
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
这就是图形的外观