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

第二弹 给绘制的物体设置颜色

时间:2015-11-21 15:42:56      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

/*************************************************************************
    > File Name: frame.cpp
    > Author:Aerk 
    > Mail: 916356609@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);
    glColor3f(1.0f,0.0f,0.0f);
    glVertex3f(0.0f,1.0f,0.0f);
    glColor3f(0.0f,1.0f,0.0f);
    glVertex3f(-1.0,-1.0,0.0f);
    glColor3f(0.0f,0.0f,1.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;
}

 

效果图:

技术分享

第二弹 给绘制的物体设置颜色

标签:

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

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