在 opengl 中画出三角形并用 shader 改变颜色

/*
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值