码迷,mamicode.com
首页 > 其他好文 > 详细

细分和边界

时间:2015-01-03 13:09:37      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

代码如下:

#include <windows.h>
//#include <GLUT/glut.h>
#include <GL/glut.h>
#include <math.h>
#include <iostream>
using namespace std;

#define GL_PI 3.1415f


void RenderScene()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    GLboolean bEdgeflag;
    glBegin(GL_TRIANGLES);
        glEdgeFlag(bEdgeflag);
        glVertex2f(-20.0f,0.0f);
        glEdgeFlag(true);
        glVertex2f(20.0f,0.0f);
        glVertex2f(0.0f,40.0f);

        glVertex2f(-20.0f,0.0f);
        glVertex2f(-60.0f,-20.0f);
        glEdgeFlag(bEdgeflag);
        glVertex2f(-20.0f,-40.0f);
        glEdgeFlag(true);

        glVertex2f(-20.0f,-40.0f);
        glVertex2f(0.0f,-80.0f);
        glEdgeFlag(bEdgeflag);
        glVertex2f(20.0f,-40.0f);
        glEdgeFlag(true);

        glVertex2f(20.0f,-40.0f);
        glVertex2f(60.0f,-20.0f);
        glEdgeFlag(bEdgeflag);
        glVertex2f(20.0f,0.0f);
        glEdgeFlag(true);

        glEdgeFlag(bEdgeflag);
        glVertex2f(-20.0f,0.0f);
        glVertex2f(-20.0f,-40.0f);
        glVertex2f(20.0f,0.0f);

        glVertex2f(-20.0f,-40.0f);
        glVertex2f(20.0f,-40.0f);
        glVertex2f(20.0f,0.0f);
        glEdgeFlag(true);

    glEnd();

    glutSwapBuffers();

}

void ChangeSize(GLsizei w,GLsizei h)
{
    if(h==0)
        h = 1;

    GLfloat aspectRatio = (GLfloat)w/(GLfloat)h;

    glViewport(0,0,w,h);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    if(w<=h)
        glOrtho(-100,100,-100/aspectRatio,100/aspectRatio,100.0,-100.0);
    else
        glOrtho(-100*aspectRatio,100*aspectRatio,-100,100,100.0,-100.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

}

void SetupRC()
{
    glClearColor(0.0f,0.0f,0.0f,1.0f);
    glColor3f(1.0f,0.0f,0.0f);
}

int main(int argc, char *argv[])
{
   glutInit(&argc,argv);
   glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
   glutInitWindowSize(800,600);
   glutCreateWindow("Simple");

   glutDisplayFunc(RenderScene);
   glutReshapeFunc(ChangeSize);

   SetupRC();
   glutMainLoop();
   return 0;
}

 

细分和边界

标签:

原文地址:http://www.cnblogs.com/lxk2010012997/p/4199340.html

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