// 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. SimpleXML 使用详细例子

    要处理XML 文件,有两种传统的处理思路:SAX 和DOM.SAX 基于事件触发机制, 对XML 文件进行一次扫描,完成要进行的处理:DOM 则将整个XML 文件构造为一棵DOM 树,通过对DOM 树 ...

  2. 常用Java片段

    1. 字符串与整型的相互转换 String a = String.valueOf(2);   //integer to numeric string int i = Integer.parseInt( ...

  3. java selenium webdriver实战 页面元素定位

    自动化测试实施过程中,测试程序中常用的页面操作有三个步骤 1.定位网页上的页面元素,并存储到一个变量中 2.对变量中存储的页面元素进行操作,单击,下拉或者输入文字等 3.设定页面元素的操作值,比如,选 ...

  4. 快速学习使用 Windows Azure 上的 SharePoint Server 2013

     为了在当今的企业环境中占据一席之地,您需要能够迅速顺应变化和应对挑战.有时,需要及时调整您的SharePoint 基础结构以保持竞争优势. 基础结构即服务可通过随时使用.即付即用的解决方案应对这 ...

  5. 国产编程语言R++ V1.5发布

    R++ v1.5内核改动较大,下面是一些主要变化: 1.使用PJIT(Pseudocode Just-In-Time),编译速度大幅提高,但运行效率远远不如C++,不过R++将在下一版本支持RJIT( ...

  6. 如何查看数据文件或者Log文件是否增长过?

    在论坛看到一个帖子,说数据库变慢了一段时间,发现这段时间数据库文件的最后修改时间跟变慢的世界一致,想知道这段时间是否文件确实增长了. 其实SQL Server提供了数据增长的Event,而且Defau ...

  7. CSS learnning...

    "Whenever this property changes, apply that change slowly." The property transition: width ...

  8. c/c++ double的数字 转成字符串后 可以有效的避免精度要求不高的数

    char n[100]; sprintf(n,"%lf",db);

  9. WINFORM Tootip使用小结

    toolTip1.Active = true;   //激活工具提示,只有激活才会显示提示 toolTip1.IsBalloon = true;    //toolTip以气泡形式出现 toolTip ...

  10. VC++ 编译过程

    一 前言 一开始编译C++代码的时候可能会对编译的错误觉得很难理解,搞不清楚究竟是哪里错了.了解编译过程,能够更好的处理编译错误. 二 名词解释 编译单元:当一个c或cpp文件在编译时,预处理器首先递 ...