zoukankan      html  css  js  c++  java
  • 实验一 OpenGL初识

    主题:实验1——OpenGL初识(计算机图形学(OpenGL版))

    代码1:

     1 #include <GL/glut.h>
     2 
     3 void myDisplay(void){
     4 
     5 glClearColor(0.0,0.0,0.0,0.0);
     6 glClear(GL_COLOR_BUFFER_BIT);
     7 
     8 glColor3f(1.0f,1.0f,1.0f);
     9 glRectf(-0.5f,-0.5f,0.5f,0.5f);
    10 
    11 glBegin (GL_TRIANGLES);
    12 glColor3f(1.0f,0.0f,0.0f);glVertex2f(0.0f,1.0f);
    13 glColor3f(0.0f,1.0f,0.0f);glVertex2f(0.8f,-0.5f);
    14 glColor3f(0.0f,0.0f,1.0f);glVertex2f(-0.8f,-0.5f);
    15 glEnd();
    16 
    17 glPointSize(3);
    18 
    19 glBegin(GL_POINTS);
    20 
    21 glColor3f(1.0f,0.0f,0.0f);glVertex2f(-0.4f,-0.4f);
    22 glColor3f(0.0f,1.0f,0.0f);glVertex2f(0.0f,0.0f);
    23 glColor3f(0.0f,0.0f,1.0f);glVertex2f(0.4f,0.4f);
    24 
    25 glEnd();
    26 
    27 
    28 glFlush();
    29 
    30 
    31 }
    32 
    33 int main(int argc,char *argv[]){
    34     glutInit(&argc,argv);
    35     glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
    36     glutInitWindowPosition(100,100);
    37     glutInitWindowSize(400,400);
    38     glutCreateWindow("Hello World!");
    39     glutDisplayFunc(&myDisplay);
    40     glutMainLoop();
    41     return 0;
    42 
    43 }

    运行结果:

     

    代码2:

     1 #include <GL/glut.h>
     2 
     3 void myDisplay(void){
     4 
     5 glClearColor(0.0,0.0,0.0,0.0);
     6 glClear(GL_COLOR_BUFFER_BIT);
     7 
     8 glColor3f(1.0f,1.0f,1.0f);
     9 glRectf(-0.5f,-0.5f,0.5f,0.5f);
    10 
    11 glBegin (GL_TRIANGLES);
    12 glColor3f(1.0f,0.0f,0.0f);glVertex2f(0.0f,1.0f);
    13 glColor3f(0.0f,1.0f,0.0f);glVertex2f(0.8f,-0.5f);
    14 glColor3f(0.0f,0.0f,1.0f);glVertex2f(-0.8f,-0.5f);
    15 glEnd();
    16 
    17 glPointSize(3);
    18 
    19 glBegin(GL_POINTS);
    20 
    21 glColor3f(1.0f,0.0f,0.0f);glVertex2f(-0.4f,-0.4f);
    22 glColor3f(0.0f,1.0f,0.0f);glVertex2f(0.0f,0.0f);
    23 glColor3f(0.0f,0.0f,1.0f);glVertex2f(0.4f,0.4f);
    24 
    25 glEnd();
    26 
    27 
    28 glBegin(GL_LINE_LOOP);
    29 
    30 glColor3f(1.0f,1.0f,1.0f);glVertex2f(0.4f,0.25f);
    31 glColor3f(1.0f,1.0f,1.0f);glVertex2f(0.0f,-0.5f);
    32 glColor3f(1.0f,1.0f,1.0f);glVertex2f(-0.4f,0.25f);
    33 
    34 glEnd();
    35 
    36 glFlush();
    37 
    38 
    39 }
    40 
    41 int main(int argc,char *argv[]){
    42     glutInit(&argc,argv);
    43     glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
    44     glutInitWindowPosition(100,100);
    45     glutInitWindowSize(400,400);
    46     glutCreateWindow("Hello World!");
    47     glutDisplayFunc(&myDisplay);
    48     glutMainLoop();
    49     return 0;
    50 
    51 }

    运行结果:

  • 相关阅读:
    转载:PHP JSON_ENCODE 不编码中文汉字的方法
    【TP3.2】:日志记录和查看
    PHP原生:分享一个轻量级的缓存类=>cache.php
    python: 基本的日期与时间转换
    python: 随机选择
    计算机bit是什么意思
    Python: 矩阵与线性代数运算
    Python numpy 安装以及处理报错 is not a supported wheel on this platform
    Python: 大型数组运算
    Python numpy有什么用?
  • 原文地址:https://www.cnblogs.com/mallocxw/p/5366623.html
Copyright © 2011-2022 走看看