// 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. hive支持sql大全

    转自:http://www.aboutyun.com/thread-7316-1-1.html 一.关系运算:1. 等值比较: = 语法:A=B 操作类型:所有基本类型 描述: 如果表达式A与表达式B ...

  2. <转>四个重要属性——Action、Data、Category、Extras

    Intent作为联系各Activity之间的纽带,其作用并不仅仅只限于简单的数据传递.通过其自带的属性,其实可以方便的完成很多较为复杂的操作.例如直接调用拨号功能.直接自动调用合适的程序打开不同类型的 ...

  3. 浅谈 non-blocking I/O Multiplexing + poll/epoll 的正确使用

    在前面的文章中曾经粗略讲过poll,那时是用阻塞IO实现,在发送和接收数据量都较小情况下和网络状况良好的情况下是基本没有问题的,read 不会只接收部分数据,write 也不会一直阻塞.但实际上pol ...

  4. 尼康D5100使用设置及技巧,同样也适用尼康D5200

    尼康D5100使用设置及技巧,同样也适用尼康D5200,希望对新手能有点帮助. 一.设置 1.优化校准:可以在menu菜单中找到它,一般使用"标准"就可以,建议将"标准& ...

  5. NET Core环境并创建运行ASP.NET网站

    kungge 在Windows系统搭建.NET Core环境并创建运行ASP.NET网站 微软于6月27日在红帽DevNation峰会上 正式发布了.NET Core 1.0.ASP.NET 1.0和 ...

  6. java中三种常见内存溢出错误的处理方法

    更多 10   相信有一定java开发经验的人或多或少都会遇到OutOfMemoryError的问题,这个问题曾困扰了我很长时间,随着解决各类问题经验的积累以及对问题根源的探索,终于有了一个比较深入的 ...

  7. Linux同平台Oracle数据库整体物理迁移

    Linux同平台数据库整体物理迁移需求:A机器不再使用,要将A机器的Oracle迁移到B机器.之前写过类似需求的文章: http://www.linuxidc.com/Linux/2015-05/11 ...

  8. discuz门户文章页面模板修改

    修改内容:view.htm 1.文章标题,模板代码 <h1 class="ph">$article[title] <!--{if $article['status ...

  9. HDU 5019 Revenge of GCD

    题解:筛出约数,然后计算即可. #include <cstdio> #include <algorithm> typedef long long LL; LL a1[10000 ...

  10. BZOJ 1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    题目 1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MB Description FJ's N ( ...