0
在OpenGL中我是新的,我試圖做一個12x15的網格,所以它看起來像一個數組,但仍然是一個網格。我有這樣的代碼至今:OpenGL繪製網格
#include <windows.h>
#include <GL/glut.h>
void display(){
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);
// Horizontal lines.
for (int i=0; i<=12; i++) {
glVertex2f(0, i);
glVertex2f(15, i);
}
// Vertical lines.
for (int i=0; i<=15; i++) {
glVertex2f(i, 0);
glVertex2f(i, 12);
}
glEnd();
glFlush();
}
void handleKeypress(unsigned char key, int x, int y){
switch (key){
case 27: //Escape key
exit(0);
}
}
main(int argc, char** argv){
glutInit(&argc, argv);
glutCreateWindow("Grid Test");
glutInitWindowSize(600, 480);
glutInitWindowPosition(100, 100);
glutDisplayFunc(display);
glutKeyboardFunc(handleKeypress);
glutMainLoop();
}
,但程序窗口有這樣的: test grid
什麼是我犯的錯?我是否應該爲顯示功能繪製網格的函數?