/* glew.h 源代码中的一些宏定义 typedef unsigned int GLenum; typedef unsigned int GLbitfield; typedef unsigned int GLuint; typedef int GLint; typedef int GLsizei; typedef unsigned char GLboolean; typedef signed char GLbyte; typedef short GLshort; typedef unsigned char GLubyte; typedef unsigned short GLushort; typedef unsigned long GLulong; typedef float GLfloat; typedef float GLclampf; typedef double GLdouble; typedef double GLclampd; typedef void GLvoid; */ #include <iostream> #define GLEW_STATIC #include <GL/glew.h> #include <GLFW/glfw3.h> void key_callback(GLFWwindow *windows, int key, int scancode, int actin, int mode); const GLuint WIDTH = 800, HEIGHT = 600; //Shaders const GLchar *vertexShaderSource = "#version 330 core\n" " \n" "layout (location = 0) in vec3 position;\n" "\n" "void main()\n" "{ \n" " gl_Position = vec4(position.x, position.y, position.z, 1.0);\n" "}"; const GLchar *fragmentShaderSource = "#version 330 core\n" "out vec4 color;\n" "void main()\n" "{ \n" "color = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" "}\n\0"; const GLchar* fragmentShaderSource2 = "#version 330 core\n" "out vec4 color;\n" "void main()\n" "{ \n" "color = vec4(1.0f, 1.0f, 0.0f, 1.0f); // The color yellow \n" "}\n\0"; int main() { glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE
在 opengl 中画出三角形并用 shader 改变颜色
最新推荐文章于 2024-06-24 14:11:51 发布