// 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. jQuery实时获取checkbox状态问题

    在最近的项目开发中,使用jQuery操作checkbox时,发现一个问题. Html代码如下: <body> <div> <inputtype="checkbo ...

  2. delphi R3下 跨进程获取DLL信息 NtQueryInformationProcess

    unit APIUnit; { GetProcessModuleHandle API Unit Ring3调用NtQueryInformationProcess实现跨进程获取DLL句柄 } inter ...

  3. 黑马12期day01之html&css

    html注释:<!-- --> html中不支持空格.回车.制表符都会被解析成一个空格 <pre></pre>标签内以上三个会被正常解析. <font> ...

  4. 测试linux和window下 jdk最大能使用多大内存

    在命令行下用 java -XmxXXXXM -version 命令来进行测试,然后逐渐的增大XXXX的值,如果执行正常就表示指定的内存大小可用,否则会打印错误信息. 发现在linux先 最多用java ...

  5. jquery 工作笔记,不断整理中..

    $('input:radio[name="ruleType"]:checked').val()  //获得radio选中的值 $("input[name='Q_lastU ...

  6. QT显示如何减轻闪屏(双缓冲和NoErase)

    很多同志在些QT 程序后会遇见闪屏的问题, 有时速度非常快,但毕竟影响了显示效果,如何做到减轻屏幕抖动或闪屏呢?我曾试过如下的办法:1.使用双缓冲. 比如我们在一个Widget里面绘多个图的话, 先创 ...

  7. 老生常谈--Js继承小结

    一直以来,对Js的继承有所认识,但是认识不全面,没什么深刻印象.于是,经常性的浪费很多时间重新看博文学习继承,今天工作不是特别忙,有幸看到了http://www.slideshare.net/stoy ...

  8. [置顶] SpecDD(混合的敏捷方法模型)主要过程概述

    敏捷已成为当今使用最广泛的开发方法.有趣的是,敏捷方法的流行性并不是因为它取代了其他开发方法,相反它与这些方法进行了更好地融合.现实世界众多敏捷项目的成功,也证明了敏捷将走向杂化的未来. SpecDD ...

  9. 如何注册成为uber司机 快速成为优步司机网上注册流程攻略 2015最新

    [目前开通Uber的城市]:北京.上海.天津.广州.成都.深圳.杭州.重庆.武汉.青岛.南京.苏州.长沙.宁波.西安.佛山等.济南,烟台和厦门正在秘密的招第一批司机. [车辆要求]:要求裸车价8万以上 ...

  10. iOS中菊花。。。

    其实系统的菊花除了功能有点单一,不具有刷新页面的功能以外,其他都还好吧,满足你一些正常的提示功能还是绰绰有余的:直接把项目里面的代码粘出来吧,其实也没有什么特别要注意的地方,一些设置属性也算留个备份 ...