码迷,mamicode.com
首页 > Windows程序 > 详细

第一弹 创建窗体,并绘制一个三角形一个矩形

时间:2015-11-21 15:46:53      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

/*************************************************************************
    > File Name: frame.cpp
    > Author:Aerk
    > Mail: 1134675716@qq.com
 ************************************************************************/

#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

效果图:
技术分享

第一弹 创建窗体,并绘制一个三角形一个矩形

标签:

原文地址:http://www.cnblogs.com/L-Arikes/p/4983734.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!