opengl 来画个三角形
来源:互联网 发布:拍淘宝送小礼品 微信 编辑:程序博客网 时间:2024/06/10 10:29
opengl 来画个三角形
这次我们通过顶点数组的方式来画三角形。
#include "glew.h"#include <glfw3.h>int main(void){GLFWwindow* window;/* Initialize the library */if (!glfwInit())return -1;/* Create a windowed mode window and its OpenGL context */window = glfwCreateWindow(480, 320, "Hello World", NULL, NULL);if (!window){glfwTerminate();return -1;}/* Make the window's context current */glfwMakeContextCurrent(window);// Needed in core profileif( glewInit() != GLEW_OK){glfwTerminate();return -1;}// An array of 3 vectors which represents 3 verticesstatic const GLfloat g_vertex_buffer_data[] = {-1.0f,-1.0f,0.0f,1.0f,-1.0f,0.0f,0.0f,1.0f,0.0f,};//This will identify our vertex bufferGLuint vertexbuffer;//Generate 1 buffer,put the resulting identifier in vertexbufferglGenBuffers(1,&vertexbuffer);//The following commands will talk about our 'vertexbuffer' bufferglBindBuffer(GL_ARRAY_BUFFER,vertexbuffer);//Give our vertices to OpenGL.glBufferData(GL_ARRAY_BUFFER,sizeof(g_vertex_buffer_data),g_vertex_buffer_data,GL_STATIC_DRAW);/* Loop until the user closes the window */while (!glfwWindowShouldClose(window)){glEnableVertexAttribArray(0);glVertexAttribPointer(0,// attribute 0. No particular reason for 0, but must match the layout in the shader.3,// sizeGL_FLOAT,// typeGL_FALSE,// normalized?0,// stride(void*)0// array buffer offset);glDrawArrays(GL_TRIANGLES,0,3);// Starting from vertex 0; 3 vertices total -> 1 triangleglDisableVertexAttribArray(0);/* Swap front and back buffers */glfwSwapBuffers(window);/* Poll for and process events */glfwPollEvents();}glfwTerminate();return 0;}
首先工程里添加glew32.lib,cpp里添加#include "glew.h",引入glew库。glewInit(),glew库初始化。
const GLfloat g_vertex_buffer_data[] 顶点数组。glGenBuffers创建buffer,glBindBuffer激活buffer(指定是哪种类型的buffer),glBufferData传入数据,glEnableVertexAttribArray开户顶点数组属性,glVertexAttribPointer设置顶点数组属性,glDrawArrays画数组,glDisableVertexAttribArray关闭顶点数组属性
0 0
- opengl 来画个三角形
- android opengl 画三角形
- OpenGL画三角形
- opengl做的三角形
- OpenGL 第一个三角形
- opengl 画三角形 程序
- OpenGL三角形几何变换
- 使用opengl绘制三角形
- OpenGL画三角形
- opengl es三角形例子
- [OpenGL]创建一个三角形
- opengl 画三角形
- WIN32 opengl三角形绘制
- OpenGL 绘制三角形
- 【OpenGL】绘制三角形
- OpenGL绘制三角形
- OpenGL 绘制简单三角形
- android opengl es--三角形,四边形
- VMware接入Openstack方案分析
- BeanDefinitionParserDelegate解读
- [LeetCode系列]卡特兰数(Catalan Number) 在求解独特二叉搜寻树(Unique Binary Search Tree)中的应用分析
- c#端口扫描器源代码
- 权重随机抽取
- opengl 来画个三角形
- php中时间加减法
- 【深入Java虚拟机】之七:Javac编译与JIT编译
- android webview js交互 (java和js交互)
- Red and Black
- 还未你等着 我的心快死了
- hdu 1114 Piggy-Bank_完全背包经典例题!
- C语言中 strlen函数用法的问题
- 大端系统和小端系统