#include "stdafx.h"
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h> using namespace std; void myDisplay(void){
glClear(GL_COLOR_BUFFER_BIT);
//glRectf(-0.5f, -0.5f, 0.5f, 0.5f); glBegin(GL_LINES);
glVertex2f(-0.5f, -0.5f); //直线起始坐标
glVertex2f(0.5f, 0.5f); //直线结束坐标
glEnd(); glBegin(GL_LINES);
glVertex2f(-0.5f, 0.5f);
glVertex2f(0.5f, -0.5f);
glEnd(); glBegin(GL_LINES);
glVertex2f(-0.5f, 0.5f);
glVertex2f(-0.5f, -0.5f);
glEnd(); glBegin(GL_LINES);
glVertex2f(0.5f, 0.5f);
glVertex2f(0.5f, -0.5f);
glEnd(); glBegin(GL_LINES);
glVertex2f(-0.5f, 0.5f);
glVertex2f(0.5f, 0.5f);
glEnd(); glBegin(GL_LINES);
glVertex2f(-0.5f, -0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd(); glBegin(GL_LINES);
glVertex2f(, 0.5f);
glVertex2f(, -0.5f);
glEnd(); glBegin(GL_LINES);
glVertex2f(-0.5f, -0.5f);
glVertex2f(0.5, -0.5f);
glEnd(); glBegin(GL_LINES);
glVertex2f(-0.5f, );
glVertex2f(0.5, );
glEnd(); glFlush();
}
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(, );
glutInitWindowSize(, );
glutCreateWindow("第一个 OpenGL 程序");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return ;
}
运行图像: