/************************************************************************* > File Name: frame.cpp > Author:Aerk > Mail: [email protected] ************************************************************************/ #include<iostream> #include<GL/glut.h> using namespace std; void init(void) { glClearColor(0.0,0.0,0.0,0.0); glMatrixMode(GL_PROJECTION); glOrtho(-10,10,-10,10,-15,15); // glMatrixMode(GL_MODELVIEW); gluLookAt(0,0,10,0,0,0,0,3,0); return; } void display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColor3f(1,0,0); glTranslatef(-2.0f,0.0f,-0.0f); // glLoadIdentity(); glBegin(GL_TRIANGLES); glVertex3f(0.0f,1.0f,0.0f); glVertex3f(-1.0,-1.0,0.0f); glVertex3f(1.0,-1.0,0.0f); glEnd(); glTranslatef(2.0f,0.0f,0.0f); glBegin(GL_QUADS); glVertex3f(-1.0f,1.0f,0.0f); glVertex3f(1.0f,1.0f,0.0f); glVertex3f(1.0f,-1.0f,0.0f); glVertex3f(-1.0f,-1.0f,0.0f); glEnd(); // glutWireTeapot(3); glFlush(); return; } int main(int argc,char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); glutInitWindowPosition(0,0); glutInitWindowSize(500,500); glutCreateWindow("OpenGL 3D View"); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }
g++ -o frame frame.cpp -lGL -lGLU -lglut
效果图:
时间: 2024-10-10 10:08:04