Skip to content

Commit

Permalink
Add vertex type and offsetof to OpenGL triangle
Browse files Browse the repository at this point in the history
  • Loading branch information
elmindreda committed May 24, 2019
1 parent f61d091 commit d44bfe0
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions examples/simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@
#include "linmath.h"

#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>

static const struct
typedef struct Vertex
{
float x, y;
float r, g, b;
} vertices[3] =
vec2 pos;
vec3 col;
} Vertex;

static const Vertex vertices[3] =
{
{ -0.6f, -0.4f, 1.f, 0.f, 0.f },
{ 0.6f, -0.4f, 0.f, 1.f, 0.f },
{ 0.f, 0.6f, 0.f, 0.f, 1.f }
{ { -0.6f, -0.4f }, { 1.f, 0.f, 0.f } },
{ { 0.6f, -0.4f }, { 0.f, 1.f, 0.f } },
{ { 0.f, 0.6f }, { 0.f, 0.f, 1.f } }
};

static const char* vertex_shader_text =
Expand Down Expand Up @@ -123,10 +126,10 @@ int main(void)

glEnableVertexAttribArray(vpos_location);
glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE,
sizeof(vertices[0]), (void*) 0);
sizeof(Vertex), (void*) offsetof(Vertex, pos));
glEnableVertexAttribArray(vcol_location);
glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE,
sizeof(vertices[0]), (void*) (sizeof(float) * 2));
sizeof(Vertex), (void*) offsetof(Vertex, col));

while (!glfwWindowShouldClose(window))
{
Expand Down

0 comments on commit d44bfe0

Please sign in to comment.