vertex colours
This commit is contained in:
parent
3d23c46fbd
commit
ea9c3fdd3a
|
@ -1,9 +1,9 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
uniform vec4 ourColor;
|
in vec3 ourColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = ourColor;
|
FragColor = vec4(ourColor, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
layout (location = 0) in vec3 aPos;
|
layout (location = 0) in vec3 aPos; // position has attribute position 0
|
||||||
|
layout (location = 1) in vec3 aColor; // color has attribute position 1
|
||||||
|
|
||||||
out vec4 vertexColor;
|
out vec3 ourColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
|
gl_Position = vec4(aPos, 1.0);
|
||||||
vertexColor = vec4(0.5, 0.0, 0.0, 1.0);
|
ourColor = aColor;
|
||||||
}
|
}
|
||||||
|
|
16
src/main.c
16
src/main.c
|
@ -3,10 +3,11 @@
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
|
||||||
float vertices[] = {
|
float vertices[] = {
|
||||||
0.5f, 0.5f, 0.0f, // top right
|
// position color
|
||||||
0.5f, -0.5f, 0.0f, // bottom right
|
0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, // top right
|
||||||
-0.5f, -0.5f, 0.0f, // bottom left
|
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom right
|
||||||
-0.5f, 0.5f, 0.0f // top left
|
-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left
|
||||||
|
-0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // top left
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int indices[] = {
|
unsigned int indices[] = {
|
||||||
|
@ -50,8 +51,13 @@ int main()
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
// set vertex attributes
|
// set vertex attributes
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), (void*)0); // TODO: wtf
|
|
||||||
|
// position attribute
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), (void*)0); // TODO: wtf
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
|
// color attribute
|
||||||
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), (void*)(3 * sizeof(float)));
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
glUseProgram(shaderProgram);
|
glUseProgram(shaderProgram);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue