iOS OpenGL ES2.0教程 Lesson03 旋转
来源:互联网 发布:语法分析算法 编辑:程序博客网 时间:2024/04/29 11:30
http://jimmyzhouj.blog.51cto.com/2317513/884763
标签: 教程 iOS OpenGL ES tutorial
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://jimmyzhouj.blog.51cto.com/2317513/884763
- //---------------------------------------------------
- //create a rectangle
- std::vector<float> geometryData;
- //vertex 0, left/buttom
- geometryData.push_back(-0.5); geometryData.push_back(-0.5); geometryData.push_back(0.0); geometryData.push_back(1.0);
- // 1, right/buttom
- geometryData.push_back(0.5); geometryData.push_back(-0.5); geometryData.push_back(0.0); geometryData.push_back(1.0);
- // 2, right/ups
- geometryData.push_back(0.5); geometryData.push_back(0.5); geometryData.push_back(0.0); geometryData.push_back(1.0);
- // 3, left/up
- geometryData.push_back(-0.5); geometryData.push_back(0.5); geometryData.push_back(0.0); geometryData.push_back(1.0);
- //generate an ID for our geometry buffer in the video memory and make it the active one
- glGenBuffers(1, &m_geometryBuffer);
- glBindBuffer(GL_ARRAY_BUFFER, m_geometryBuffer);
- //send the data to the video memory
- glBufferData(GL_ARRAY_BUFFER, geometryData.size() * sizeof(float), &geometryData[0], GL_STATIC_DRAW);
- //create a color buffer, to make our triangle look pretty
- std::vector<float> colorData;
- //3 floats define one color value (red, green and blue) with 0 no intensity and 1 full intensity
- //each color triplet is assigned to the vertex at the same position in the buffer, so first color -> first vertex
- //vertex 0 is red
- colorData.push_back(1.0); colorData.push_back(0.0); colorData.push_back(0.0);
- // 1 is blue
- colorData.push_back(0.0); colorData.push_back(0.0); colorData.push_back(1.0);
- // 2 is green
- colorData.push_back(0.0); colorData.push_back(1.0); colorData.push_back(0.0);
- // 3 is blue
- colorData.push_back(0.0); colorData.push_back(0.0); colorData.push_back(1.0);
- //generate an ID for the color buffer in the video memory and make it the active one
- glGenBuffers(1, &m_colorBuffer);
- glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer);
- //send the data to the video memory
- glBufferData(GL_ARRAY_BUFFER, colorData.size() * sizeof(float), &colorData[0], GL_STATIC_DRAW);
- //create vertex indices
- std::vector<GLubyte> indexData;
- //3 byte define 1 triangle
- indexData.push_back(0); indexData.push_back(1); indexData.push_back(2);
- indexData.push_back(2); indexData.push_back(3); indexData.push_back(0);
- m_indexNumber = indexData.size();
- //generate an ID for the index buffer in video memory
- glGenBuffers(1, &m_indexBuffer);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
- //send data to video memory
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexData.size() * sizeof(GLubyte), &indexData[0], GL_STATIC_DRAW);
- //initiate the drawing process, we want a triangle, start at index 0 and draw 3 vertices
- glDrawArrays(GL_TRIANGLES, 0, 3);
- //initiate the drawing process
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
- glDrawElements(GL_TRIANGLES, m_indexNumber, GL_UNSIGNED_BYTE, 0);
- // modelview
- uniform mat4 modelview;
- //the shader entry point is the main method
- void main()
- {
- colorVarying = color; //save the color for the fragment shader
- gl_Position = modelview * position; //copy the position
- }
- //modelview uniform in the shader
- int m_modelview;
- Lesson03.mm:
- //get the attachment points for modelview
- m_modelview = glGetUniformLocation(m_shader->getProgram(), "modelview");
- //check
- if (m_modelview < 0) {
- NSLog(@"Could not query uniform location");
- }
- //modelview
- CC3GLMatrix *mvMatrix = [CC3GLMatrix matrix];
- [mvMatrix populateFromTranslation:CC3VectorMake(0.2, 0 , 0)];
- m_currentRotation += 1.0;
- [mvMatrix rotateBy:CC3VectorMake(0, m_currentRotation, 0)];
- glUniformMatrix4fv(m_modelview, 1, 0, mvMatrix.glMatrix);
0 0
- iOS OpenGL ES2.0教程 Lesson03 旋转
- iOS OpenGL ES2.0教程 Lesson03 旋转 投影矩阵,相机矩阵,世界矩阵生效
- OpenGL ES2.0教程:初识MVP(3)
- OpenGL ES2.0教程:纹理贴图(6)
- OpenGL ES2.0之iOS基础<一>
- iOS OpenGL ES2.0 开发实例
- OpenGL ES2.0之iOS基础<一>
- iOS OpenGL ES2.0 开发实例
- 初识openGL ES2.0
- OpenGL ES2.0 初步
- OpenGL ES2.0基础
- Android OpenGL ES2.0
- OpenGL ES2.0教程:编写自己的shader(2)
- OpenGL ES2.0教程:使用VBO索引(4)
- OpenGL ES2.0教程:你的第一个立方体(5)
- OpenGL ES2.0教程(3):初识MVP
- OpenGL ES2.0教程:编写自己的shader(2)
- OpenGL ES2.0教程:编写自己的shader
- Android Library Project自定义控件属性无法找到说明
- android下简单的网络图片查看器
- [jimmyzhouj 翻译] Nehe iOS OpenGL ES 2.0教程 --Lesson 02
- 视图的单击,双击,捏合,扫动,旋转,长按等。
- 数据库及JDBC技术
- iOS OpenGL ES2.0教程 Lesson03 旋转
- hdu 1054 最小点覆盖
- POJ 2081 Recaman's Sequence
- 深入学习python (六) 用sched来定时执行任务
- iOS OpenGL ES 2.0教程 Lesson04--3D空间
- EditText 去边框
- Unity3d中MicroPhone的使用
- Linux下C语言的多线程编程学习[写得很好哦]
- java synchronized详解