程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> 第一彈 創建窗體,並繪制一個三角形一個矩形,

第一彈 創建窗體,並繪制一個三角形一個矩形,

編輯:C++入門知識

第一彈 創建窗體,並繪制一個三角形一個矩形,


/*************************************************************************
    > 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

效果圖:

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved