直接画

#include <windows.h>
#include <GL/glut.h>
#include <stdio.h>
#include <string>
#include <iostream> // 绘制立方体 // 将立方体的八个顶点保存到一个数组里面 static const float vertex_list[][3] =
{
-0.5f, -0.5f, -0.5f,//0
0.5f, -0.5f, -0.5f,//1
-0.5f, 0.5f, -0.5f,//2
0.5f, 0.5f, -0.5f,//3 -0.5f, -0.5f, 0.5f,//4
0.5f, -0.5f, 0.5f,//5
-0.5f, 0.5f, 0.5f,//6
0.5f, 0.5f, 0.5f,//7
}; // 将要使用的顶点的序号保存到一个数组里面 static const GLint index_list[][3] =
{
0,5,1,
0,4,5,
0,3,1,
0,3,2,
0,6,2,
0,6,4,
5,6,4,
5,6,7,
5,3,1,
5,3,7,
3,6,2,
3,6,7, }; // 绘制立方体 void DrawCube(void)
{
int i, j; glBegin(GL_TRIANGLES);
for (i = 0; i<12; ++i) // 12 三角形 {
for (j = 0; j<3; ++j) // 每个三角形3顶点 {
glVertex3fv(vertex_list[index_list[i][j]]);
}
}
glEnd();
} static float rotate = 0;
static int times = 0; void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix(); /*glTranslatef(-0.2, 0, 0);*/ // 平移 //glScalef(2, 1, 1); // 缩放 times++;
if (times > 100)
{
times = 0;
} if (times % 100 == 0)
{
rotate += 2;
} glRotatef(rotate, 1, 0, 0);
glRotatef(rotate, 0, 1, 0); glColor3f(0, 0, 1); DrawCube(); glPopMatrix();
glutSwapBuffers();
} void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(500, 500);
glutCreateWindow("GLDemo");
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
glutMainLoop();
}

GL_TRIANGLE_STRIP方法

#include <windows.h>
#include <GL/glut.h>
#include <stdio.h>
#include <string>
#include <iostream> // 绘制立方体 // 将立方体的八个顶点保存到一个数组里面 static const float vertex_list[][3] =
{
-0.5f, -0.5f, -0.5f,//0
0.5f, -0.5f, -0.5f,//1
-0.5f, 0.5f, -0.5f,//2
0.5f, 0.5f, -0.5f,//3 -0.5f, -0.5f, 0.5f,//4
0.5f, -0.5f, 0.5f,//5
-0.5f, 0.5f, 0.5f,//6
0.5f, 0.5f, 0.5f,//7
}; void display(void){ glBegin(GL_TRIANGLE_STRIP);
glVertex3fv(vertex_list[0]);
glVertex3fv(vertex_list[1]);
glVertex3fv(vertex_list[2]);
glVertex3fv(vertex_list[3]);
glVertex3fv(vertex_list[6]);
glVertex3fv(vertex_list[7]);
glVertex3fv(vertex_list[4]);
glVertex3fv(vertex_list[5]);
glVertex3fv(vertex_list[0]);
glVertex3fv(vertex_list[1]);
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glVertex3fv(vertex_list[0]);
glVertex3fv(vertex_list[2]);
glVertex3fv(vertex_list[4]);
glVertex3fv(vertex_list[6]);
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glVertex3fv(vertex_list[1]);
glVertex3fv(vertex_list[3]);
glVertex3fv(vertex_list[5]);
glVertex3fv(vertex_list[7]);
glEnd();
}
static float rotate = 0;
static int times = 0; void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix(); /*glTranslatef(-0.2, 0, 0);*/ // 平移 //glScalef(2, 1, 1); // 缩放 if (times > 100)
{
times = 0;
} if (times % 100 == 0)
{
rotate += 0.3;
} glRotatef(rotate, 0, 1, 0);
glRotatef(rotate, 0, 1, 1); /*gluLookAt(0.0, 0.99, 0.10, 0.0, .0, 0.0, 0.0, 1.0, 0.0);*/ glColor3f(0, 0, 1); display(); glPopMatrix();
glutSwapBuffers();
} void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(500, 500);
glutCreateWindow("GLDemo");
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
glutMainLoop();
}

OpenGL立方体的更多相关文章

  1. OpenGL立方体在世界坐标系中_缩放_旋转_平移_顶点片源着色器_光照作用_棋盘纹理贴图

    读取bmp等图片格式中的像素还有难度,就先用这个棋盘图象素来弄了 代码打错一个就一直First-chance exception ,貌似还有一个要用q或者Q才能成功退出,不知道缺少哪句,我用窗口红叉退 ...

  2. 46.Qt 使用OpenGL绘制立方体

    main.cpp #include <QApplication> #include <iostream> #include "vowelcube.h" in ...

  3. Bullet物理引擎在OpenGL中的应用

    Bullet物理引擎在OpenGL中的应用 在开发OpenGL的应用之时, 难免要遇到使用物理来模拟OpenGL中的场景内容. 由于OpenGL仅仅是一个关于图形的开发接口, 因此需要通过第三方库来实 ...

  4. 几个opengl立方体绘制案例

    VC6 下载 http://blog.csdn.net/bcbobo21cn/article/details/44200205 opengl环境配置 http://blog.csdn.net/bcbo ...

  5. 【OpenGL】---认识CubeTexture

    一.OpenGL Cube Texture 立方体纹理 立方体纹理是一种特殊的纹理技术,他用6幅二维贴图构成一个以原点为中心的纹理立方体.对于每个片段,纹理坐标(s,t,r)被当做三维向量看待,每个纹 ...

  6. VLC命令参数(转载)

    转载自: http://blog.csdn.net/bytxl/article/details/6613449 http://www.cnblogs.com/MikeZhang/archive/201 ...

  7. VLC命令行参数详解

    VLC命令行参数详解 2012-11-29 14:00 6859人阅读 评论(0) 收藏 举报 Usage: vlc [options] [stream] ...You can specify mul ...

  8. opengl典型例程立方体投影与地图绘制

    立方体投影 http://www.cnblogs.com/opengl/p/3790450.html 地图绘制 http://www.cnblogs.com/opengl/p/3790354.html

  9. OpenGL的几何变换2之内观察立方体

    我想实现的一个场景是:一个立方体,相机的坐标在立方体的中心点,相机不变,立方体旋转,可以站在立方体中心点查看立方体内部. 实际上就是立方体图像,这是在全景图片当作比较简单的方式,画面不会变形和扭曲,但 ...

随机推荐

  1. 递归算法之Fibonacci 斐波那契数列第n个数的求解

    Fibonacci 斐波那契数列第n个数的求解,也可以用递归和非递归的形式实现,具体如下,dart语言实现. int fibonacci(int n) { if (n <= 0) throw S ...

  2. CentOS 7安装Python 2.6(与已有版本共存)

    1. 安装需要用到的包 yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget 2. 下载 Python 2.6.8 版本 w ...

  3. Linux 環境下安裝swoole

    一.先安装依赖 yum -y install gcc gcc-c++ autoconf automake yum -y install zlib zlib-devel openssl openssl- ...

  4. linux查找进程id和杀死进程以及查看内存??

    ps 命令用于查看当前正在运行的进程 ps ax : 显示当前系统进程的列表 ps aux : 显示当前系统进程详细列表以及进程用户 -e 显示所有进程,环境变量 此参数的效果和指定"A&q ...

  5. FFmpeg SDK开发模型之中的一个:解码器

    简单介绍 本例解说了怎样使用ffmpeg SDK解码媒体文件: 參考源代码是ffmpeg 自带的apiexample.c 一.源代码#include <stdlib.h>#include ...

  6. 简单的物流项目实战,WPF的MVVM设计模式(五)

    开始界面 <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> <RowD ...

  7. arcgis server10.2发布地图服务报错

    发布地图服务时,读取了本机电脑中的切片方案.发布服务,报打包成功,但发布失败错误. 解决办法:给arcgis账户,赋予读写权限即可.重复发布服务,成功发布.

  8. http参数传递方式

    url传参 这种在各种method(get,post,delete,put)都能使用,解析速度快 body体中的参数 application/x-www-form-urlencoded 这应该是最常见 ...

  9. nginx在windows下配置反向代理

    转自:https://blog.csdn.net/comeonyangzi/article/details/72466310 下载地址:http://nginx.org/download/ 下载后直接 ...

  10. Python爬虫之urllib.parse详解

    Python爬虫之urllib.parse 转载地址 Python 中的 urllib.parse 模块提供了很多解析和组建 URL 的函数. 解析url 解析url( urlparse() ) ur ...