OpenGL学习(五) 几何图形
来源:互联网 发布:微信附近人v1数据采集 编辑:程序博客网 时间:2024/06/06 08:57
// GeoTest.cpp// OpenGL SuperBible// Demonstrates OpenGL Backface culling, depth testing, and polygon mode// Program by Richard S. Wright Jr.#include <GLTools.h>// OpenGL toolkit#include <GLMatrixStack.h>#include <GLFrame.h>#include <GLFrustum.h>#include <GLGeometryTransform.h>#include <math.h>#ifdef __APPLE__#include <glut/glut.h>#else#define FREEGLUT_STATIC#include <GL/glut.h>#endifGLFrame viewFrame;GLFrustum viewFrustum;GLTriangleBatch torusBatch;GLMatrixStack modelViewMatix;GLMatrixStack projectionMatrix;GLGeometryTransform transformPipeline;GLShaderManager shaderManager;// Flags for effectsint iCull = 0;int iDepth = 0;///////////////////////////////////////////////////////////////////////////////// Reset flags as appropriate in response to menu selectionsvoid ProcessMenu(int value){switch(value){case 1:iDepth = !iDepth;break;case 2:iCull = !iCull;break; case 3: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); break; case 4: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); break; case 5: glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); break;}glutPostRedisplay();}// Called to draw scenevoid RenderScene(void){// Clear the window and the depth bufferglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Turn culling on if flag is setif(iCull)glEnable(GL_CULL_FACE);elseglDisable(GL_CULL_FACE);// Enable depth testing if flag is setif(iDepth)glEnable(GL_DEPTH_TEST);elseglDisable(GL_DEPTH_TEST); modelViewMatix.PushMatrix(viewFrame); GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f }; //shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vRed); shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, transformPipeline.GetModelViewMatrix(), transformPipeline.GetProjectionMatrix(), vRed); torusBatch.Draw(); modelViewMatix.PopMatrix(); glutSwapBuffers();}// This function does any needed initialization on the rendering// context. void SetupRC(){// Black backgroundglClearColor(0.3f, 0.3f, 0.3f, 1.0f ); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(7.0f); // Make the torus gltMakeTorus(torusBatch, 1.0f, 0.3f, 52, 26); glPointSize(4.0f);}void SpecialKeys(int key, int x, int y){if(key == GLUT_KEY_UP)viewFrame.RotateWorld(m3dDegToRad(-5.0), 1.0f, 0.0f, 0.0f);if(key == GLUT_KEY_DOWN)viewFrame.RotateWorld(m3dDegToRad(5.0), 1.0f, 0.0f, 0.0f); if(key == GLUT_KEY_LEFT)viewFrame.RotateWorld(m3dDegToRad(-5.0), 0.0f, 1.0f, 0.0f); if(key == GLUT_KEY_RIGHT)viewFrame.RotateWorld(m3dDegToRad(5.0), 0.0f, 1.0f, 0.0f);// Refresh the WindowglutPostRedisplay();}void ChangeSize(int w, int h){// Prevent a divide by zeroif(h == 0)h = 1;// Set Viewport to window dimensions glViewport(0, 0, w, h); viewFrustum.SetPerspective(35.0f, float(w)/float(h), 1.0f, 100.0f); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); transformPipeline.SetMatrixStacks(modelViewMatix, projectionMatrix);}///////////////////////////////////////////////////////////////////////////////// Main entry point for GLUT based programsint main(int argc, char* argv[]) {gltSetWorkingDirectory(argv[0]);glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);glutInitWindowSize(800, 600);glutCreateWindow("Geometry Test Program"); glutReshapeFunc(ChangeSize); glutSpecialFunc(SpecialKeys); glutDisplayFunc(RenderScene); // Create the Menu glutCreateMenu(ProcessMenu); glutAddMenuEntry("Toggle depth test",1); glutAddMenuEntry("Toggle cull backface",2); glutAddMenuEntry("Set Fill Mode", 3); glutAddMenuEntry("Set Line Mode", 4); glutAddMenuEntry("Set Point Mode", 5); glutAttachMenu(GLUT_RIGHT_BUTTON); GLenum err = glewInit();if (GLEW_OK != err) {fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));return 1; }SetupRC(); glutMainLoop();return 0; }
1 0
- OpenGL学习(五) 几何图形
- 几何图形案例(openGL)
- OpenGL入门学习(五)
- OpenGL入门学习(五)
- OpenGL入门学习(五)
- OpenGL入门学习(五)
- OpenGL入门学习(五)
- OPENGL学习笔记(五)
- OpenGL学习总结(五)
- OpenGL学习笔记(五)
- OpenGL入门学习[二] 绘制简单的几何图形
- OpenGL入门学习——第二课 绘制几何图形
- OpenGL入门学习之二——绘制几何图形
- OpenGL 绘制几何图形
- OpenGL 绘制几何图形
- Android OpenGL ES(七):基本几何图形定义
- OpenGL入门学习(五) 【转】
- 学习OpenGL(五)绘制多边形
- qt 获取文件夹中文件名
- openGL学习(四) 混合效果
- jellybean的suspend策略变动
- KMP专题【完结】
- live555 sink 接收内存管理---丢帧策略
- OpenGL学习(五) 几何图形
- 图像处理和计算机视觉中的经典论文
- Eclipse常用快捷键
- ant集成maven
- ffmpeg parse_options函数解析
- WINDOWS下的APK反编译
- 最短路专题【完结】
- Android linux的休眠和唤醒
- PHP源码学习中的收获与总结