This commit is contained in:
2026-04-11 19:57:48 +08:00
Unverified
parent 468498ed74
commit 9b639938ed
3 changed files with 9 additions and 3 deletions

View File

@@ -1,15 +1,19 @@
#include<GL/glut.h>
using namespace std;
// 回调函数
void myDisplay()
{
// 清除缓冲区
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
// 正交模式
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 500.0, 0.0, 500.0);
glColor4f(0.0, 1.0, 0.0, 0.0);
glRectf(50.0, 50.0, 400.0, 400.0);
// 划线
glColor3f(1.0, 1.0, 0.0);
glBegin(GL_LINES);
glVertex2f(50.0, 50.0);
@@ -18,12 +22,14 @@ void myDisplay()
glVertex2f(50.0, 400.0);
glEnd();
// 画点
glColor3f(1.0, 0.0, 0.0);
glPointSize(20.0);
glBegin(GL_POINTS);
glVertex2f(15.0, 15.0);
glEnd();
// 画三角形
glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.0, 1.0);
glVertex2i(200, 300);
@@ -41,7 +47,7 @@ int main(int argc, char* argv[])
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(500, 500);
glutCreateWindow("ÀÖÒâ");
glutCreateWindow("The First OpenGL Program");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;