openGL 超级宝典第五版学习 第一个程序
2013-12-26 12:20
417 查看
以前一直用code block12.11写openGL,但那时还用的第四版宝典。第五版第六版用code block觉得特别无语,最后不得已改用了vosual studio 2008express 。折腾了一上午成功写出第一个
显示三角形的例子。
编译之后可以运行了。但是因为库冲突有警告,还不知道怎么解决。程序调用了数里的函数库,请大家自己下载。
显示三角形的例子。
// Triangle.cpp // Our first OpenGL program that will just draw a triangle on the screen. #include <GLTools.h> // OpenGL toolkit #include <GLShaderManager.h> // Shader Manager Class #ifdef __APPLE__ #include <glut/glut.h> // OS X version of GLUT #else #define FREEGLUT_STATIC #include <GL/glut.h> // Windows FreeGlut equivalent #endif GLBatch triangleBatch; GLShaderManager shaderManager; /////////////////////////////////////////////////////////////////////////////// // Window has changed size, or has just been created. In either case, we need // to use the window dimensions to set the viewport and the projection matrix. void ChangeSize(int w, int h) { glViewport(0, 0, w, h); } /////////////////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering context. // This is the first opportunity to do any OpenGL related tasks. void SetupRC() { // Blue background glClearColor(0.0f, 0.0f, 1.0f, 1.0f ); shaderManager.InitializeStockShaders(); // Load up a triangle GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f }; triangleBatch.Begin(GL_TRIANGLES, 3); triangleBatch.CopyVertexData3f(vVerts); triangleBatch.End(); } /////////////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f }; shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed); triangleBatch.Draw(); // Perform the buffer swap to display back buffer glutSwapBuffers(); } /////////////////////////////////////////////////////////////////////////////// // Main entry point for GLUT based programs int main(int argc, char* argv[]) { gltSetWorkingDirectory(argv[0]); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL); glutInitWindowSize(800, 600); glutCreateWindow("Triangle"); glutReshapeFunc(ChangeSize); glutDisplayFunc(RenderScene); GLenum err = glewInit(); if (GLEW_OK != err) { fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err)); return 1; } SetupRC(); glutMainLoop(); return 0; }
编译之后可以运行了。但是因为库冲突有警告,还不知道怎么解决。程序调用了数里的函数库,请大家自己下载。
相关文章推荐
- Ubuntu10.04安装Mesa及使用OpenGL超级宝典第五版demo程序
- OpenGL入门学习——第一课 编写第一个OpenGL程序
- opengl super bible(超级宝典)第五版阅读笔记
- OpenGL学习-------visual studio 2010配置和第一个OpenGL程序讲解
- [OpenGL学习] openGL超级宝典 无法打开文件“freeglut_static.lib”
- 学习OpenGL超级宝典(OpenGL superbible)的第一个程序
- openGL 超级宝典第五版 vs环境配置
- [OpenGL学习] openGL超级宝典 无法打开文件“freeglut_static.lib”
- OpenGL学习——第二课:第一个OpenGL程序
- OpenGL入门学习之一——编写第一个OpenGL程序
- 学习opengl(一)opengl 超级宝典 第5版 vs2013+opengl配置
- 《OpenGL 超级宝典(Super Bible)第五版》 有关 PBO 的 Example
- OpenGL 3D 超级宝典学习笔记
- OpenGL学习(二)第一个程序
- openGL 学习1--ubuntu中安装openGL与第一个绘图程序
- OpenGL 超级宝典(第五版) 源代码的问题(一)
- OpenGL超级宝典完整源码(第五版)
- OpenGL学习笔记一。第一个程序
- OpenGL 超级宝典学习,制作 圆柱,球体,花托,圆盘等多边体