#include <stdlib.h>
#include<iostream>
#include<GL/glew.h>
#include<GL/glut.h>
#include <opencv.hpp>
void userInit(); //自定义初始化
void display(void);
GLuint VAO;
GLuint VBO;
GLuint EBO;
GLuint texture1;
GLuint texture2;
unsigned int vertexShader;
unsigned int fragmentShader;
unsigned int shaderProgram;
float vertices[] = {
// positions // colors // texture coords
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, // top right
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, // bottom right
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, // bottom left
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f // top left
};
unsigned int indices[] = {
0, 1, 3, // first triangle
1, 2, 3 // second triangle
};
const char* vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"layout (location = 1) in vec3 aColor;\n"
"layout (location = 2) in vec2 aTexCoord;\n"
"out vec3 ourColor;\n"
"out vec2 TexCoord;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(aPos, 1.0);\n"
"ourColor = aColor;\n"
"TexCoord = vec2(aTexCoord.x, aTexCoord.y);\n"
"}\n";
const char* fragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"in vec3 ourColor; \n"
"in vec2 TexCoord; \n"
"uniform sampler2D texture1; \n"
"uniform sampler2D texture2; \n"
"void main()\n"
"{\n"
"FragColor = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), 0.5); \n"
//"FragColor = texture(texture2 , TexCoord) * vec4(ourColor, 1.0);\n"
"}\n";
int main(int argc, char**argv)
{
glutInit(
OpenGL使用GLSL对两个纹理叠加
最新推荐文章于 2024-12-11 19:33:52 发布