// lession4.c

#include <OpenGL/OpenGL.h>
#include <GLUT/GLUT.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> /* ASCII code for teh escape key. */
#define ESCAPE 27 /* The number of our GLUT window */
int window; /* rotation angle for the triangle. */
float rtri = 0.0f; /* rotation angle for the quadrilateral. */
float rquad = 0.0f; /* A general OpenGL initialization function. Sets all of the initial parameters. */
// We call this right after our OpoenGL window is created.
void initGL(int width, int height) {
// This will clear The background color to black.
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0); // Enables clearing of the depth buffer
glDepthFunc(GL_LESS); // The type of test to do.
glEnable(GL_DEPTH_TEST); // Enables depth testing.
glShadeModel(GL_SMOOTH); // Enalbes smooth color shading. glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Reset the projection matrix. // calculate the aspect ratio of the window.
gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 0.1f, 100.0f); glMatrixMode(GL_MODELVIEW);
} /* The function called when our window is resized (which shouldn't happend,
because we're fullscreen) */
void resizeGLScene(int width, int height) {
if (height == 0) // Prevent a divide by zero if the window is too small.
height = 1; glViewport(0, 0, width, height); // Reset the current viewport and perspective transformation glMatrixMode(GL_PROJECTION);
glLoadIdentity(); gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
} /* The main drawing function. */
void drawGLScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the screen and the depth buffer
glLoadIdentity(); // Reset the view. glTranslatef(-1.5f, 0.0f, -6.0f); // Move left 1.5 units and into the screen 6.0. glRotatef(rtri, 0.0f, 1.0f, 0.0f); // Rotate the triangle on the y axis
// Draw a triangel (in smooth coloring mode)
glBegin(GL_POLYGON); // Start drawing a polygon
glColor3f(1.0f, 0.0f, 0.0f); // set the color to red
glVertex3f(0.0f, 1.0f, 0.0f); // top glColor3f(0.0f, 1.0f, 0.0f); // set the color to green.
glVertex3f(1.0f, -1.0f, 0.0f); // bottom right glColor3f(0.0f, 0.0f, 1.0f); // set the color to blue.
glVertex3f(-1.0f, -1.0f, 0.0f); // bottom left.
glEnd(); // we're done with the polygon (smooth color interpolation) glLoadIdentity(); // make sure we're no longer rotated.
glTranslatef(1.5f, 0.0f, -6.0f); // Move Right 3 Units, and back into the screen 6.0 glRotatef(rquad, 1.0f, 0.0f, 0.0f); // Roate the quad on the x axis
// Draw a square (quadrilateral)
glColor3f(0.5f, 0.5f, 1.0f); // set color to a blue shade. glBegin(GL_QUADS); // Start drawing a polygon (4 sides);
glVertex3f(-1.0f, 1.0f, 0.0f); // top left.
glVertex3f( 1.0f, 1.0f, 0.0f); // top right.
glVertex3f( 1.0f, -1.0f, 0.0f); // bottom right.
glVertex3f(-1.0f, -1.0f, 0.0f); // bottom left.
glEnd(); // done with the polygon. rtri += 15.0f; // Increase the rotation variable for the triangle
rquad -= 15.0f; // decrease the rotation variable for the quad. // swap the buffers to display, since double buffering in used.
glutSwapBuffers();
} /* The function called whenever a key is pressed. */
void keyPressed(unsigned char key, int x, int y) {
/* sleep to avoid thrashing this procedure */
usleep(100); /* If escape is pressed, kill everything. */
if (key == ESCAPE) {
/*shut down our window */
glutDestroyWindow(window); /* exit the program...normal termination. */
exit(0);
}
} int main(int argc, char **argv) {
glutInit(&argc, argv); /* Select type of display mode:
Double buffer
RGBA color
Alpha components supported
Depth buffer */
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH); /* Get a 640 x 480 window */
glutInitWindowSize(640, 480); /* the window starts at teh upper left corner of the screen */
glutInitWindowSize(0, 0); /* Openg a window */
window = glutCreateWindow("Jeff Molofee's GL Code Tutorial ... NeHe '99"); /* Register the function to do all our OpenGL drawing. */
glutDisplayFunc(&drawGLScene); /* Go full screen. This is as soon as possible. */
// glutFullScreen(); /* Even if there are not events, redarw our gl scene. */
glutIdleFunc(&drawGLScene); /* register the function called when our window is resized. */
glutReshapeFunc(&resizeGLScene); /* Register the function claled when teh keyboard is pressed. */
glutKeyboardFunc(&keyPressed); /* Initialize our window. */
initGL(640, 480); /* start event processing engine. */
glutMainLoop(); return 1;
}

主要介绍了旋转

塞塞塞

NeHe OpenGL lession 4的更多相关文章

  1. Nehe Opengl

    http://nehe.gamedev.net/tutorial/lessons_01__05/22004/ Nehe Opengl,据说从基础到高端进阶都是很好的教程,准备学习这个序列,顺便记录下随 ...

  2. NeHe OpenGL教程 第四十八课:轨迹球

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  3. NeHe OpenGL教程 第四十七课:CG顶点脚本

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  4. NeHe OpenGL教程 第四十五课:顶点缓存

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  5. NeHe OpenGL教程 第四十六课:全屏反走样

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  6. NeHe OpenGL教程 第四十四课:3D光晕

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  7. NeHe OpenGL教程 第四十三课:FreeType库

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  8. NeHe OpenGL教程 第四十一课:体积雾气

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  9. NeHe OpenGL教程 第四十二课:多重视口

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

随机推荐

  1. find: missing argument to `-exec'

    man find 发现 花括号要加 '' find ${LOG_BASE_DIR}$dir/ -type f -mtime +${KEEP_DAYS} -name ${LOG_REG} -exec r ...

  2. js中递归解析xml

    xml结构: <RightMenuItems>  <Item Code="New" Name="新建" GroupCode="Edi ...

  3. MacOS Apache配置

    仅适用于apache 2.2版本   查看版本 sudo apachectl -v   启动服务器 sudo apachectl start 打开localhost,可以看到内容为“It works! ...

  4. NYOJ 14 会场安排问题(也算是经典问题了)

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工作就 ...

  5. Win7搭建Django开发环境

    1.官网下载并安装python 2.7.5 2.配置python 环境变量 在Path中加入python安装目录: PATH=PATH;c:\python26 在PATHEXT中加入以下变量,可以直接 ...

  6. Hadoop-04-HBase全然分布式环境搭建

    Hbase分布式具体安装步骤 Hadoop全然分布式环境已经搭建完毕(參见01_Hadoop全然分布式环境搭建). 注意:Hbase和Hadoop的版本号必须相应! 不然会出现各种问题! 这里选用的是 ...

  7. 不是技术牛人,如何拿到国内IT巨头的Offer(1)

    转自:http://developer.51cto.com/art/201404/436685.htm 不久前,byvoid面阿里星计划的面试结果截图泄漏,引起无数IT屌丝的羡慕敬仰.看看这些牛人,N ...

  8. web浏览器中的javascript 1

    Html 文档嵌入客户端有4种方式. 1. 内联.放置在<script>和</script>标签对之间. 2.放置在<script>标签的src属性指定的外部文件中 ...

  9. ASPxGridview必须设置ShowVerticalScrollBar为true才能动态改变高度。。。

    ASPxGridview必须设置ShowVerticalScrollBar为true才能动态改变高度... 设置 ShowVerticalScrollBar=true ,这时client-side s ...

  10. TabelView的多选模式

    @interface ViewController ()<UITableViewDelegate,UITableViewDataSource> @property(nonatomic,st ...