feat: control color (playing with opengl)
This commit is contained in:
23
main.cpp
23
main.cpp
@@ -35,17 +35,21 @@ static float boxSpeed = 250.f;
|
|||||||
const char* vShader = "#version 300 es\n"
|
const char* vShader = "#version 300 es\n"
|
||||||
"layout (location = 0) in vec2 aPos;\n"
|
"layout (location = 0) in vec2 aPos;\n"
|
||||||
"uniform mat4 uTransform;\n"
|
"uniform mat4 uTransform;\n"
|
||||||
|
"uniform vec4 uColor;\n"
|
||||||
|
"out vec4 color;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" gl_Position = uTransform * vec4(aPos, 0.0, 1.0);\n"
|
" gl_Position = uTransform * vec4(aPos, 0.0, 1.0);\n"
|
||||||
|
" color = uColor;\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
const char* fShader = "#version 300 es\n"
|
const char* fShader = "#version 300 es\n"
|
||||||
"precision mediump float;\n"
|
"precision mediump float;\n"
|
||||||
"out vec4 FragColor;\n"
|
"out vec4 fragColor;\n"
|
||||||
|
"in vec4 color;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" FragColor = vec4(1.0, 0.2, 0.3, 1.0); // red-ish\n"
|
" fragColor = color;\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
void makeRotationZ(float angle, float* m)
|
void makeRotationZ(float angle, float* m)
|
||||||
@@ -173,6 +177,11 @@ extern "C" int APP_MAIN(int argc, char **argv) {
|
|||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
float transform[16];
|
float transform[16];
|
||||||
|
float color[4];
|
||||||
|
color[0] = 0x18 / 255.f;
|
||||||
|
color[1] = 0xFF / 255.f;
|
||||||
|
color[2] = 0x18 / 255.f;
|
||||||
|
color[3] = 0xFF / 255.f;
|
||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
@@ -202,12 +211,16 @@ extern "C" int APP_MAIN(int argc, char **argv) {
|
|||||||
|
|
||||||
float angle = SDL_GetTicks() / 1000.0f; // rotates over time
|
float angle = SDL_GetTicks() / 1000.0f; // rotates over time
|
||||||
|
|
||||||
float transform[16];
|
|
||||||
makeRotationZ(angle, transform);
|
makeRotationZ(angle, transform);
|
||||||
|
|
||||||
GLuint loc = glGetUniformLocation(program, "uTransform");
|
GLuint tranformLoc = glGetUniformLocation(program, "uTransform");
|
||||||
|
GLuint colorLoc = glGetUniformLocation(program, "uColor");
|
||||||
|
|
||||||
glUseProgram(program);
|
glUseProgram(program);
|
||||||
glUniformMatrix4fv(loc, 1, GL_FALSE, transform);
|
glUniformMatrix4fv(tranformLoc, 1, GL_FALSE, transform);
|
||||||
|
|
||||||
|
color[1] = (float)((int)angle * 10 % 255) / 255.f;
|
||||||
|
glUniform4fv(colorLoc, 1, color);
|
||||||
|
|
||||||
glBindVertexArray(vao);
|
glBindVertexArray(vao);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user