mirror of
https://github.com/glfw/glfw.git
synced 2024-11-25 22:14:34 +00:00
Add vertex type and offsetof to OpenGL triangle
This commit is contained in:
parent
f61d0916fd
commit
d44bfe0264
@ -30,17 +30,20 @@
|
|||||||
#include "linmath.h"
|
#include "linmath.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static const struct
|
typedef struct Vertex
|
||||||
{
|
{
|
||||||
float x, y;
|
vec2 pos;
|
||||||
float r, g, b;
|
vec3 col;
|
||||||
} vertices[3] =
|
} Vertex;
|
||||||
|
|
||||||
|
static const Vertex vertices[3] =
|
||||||
{
|
{
|
||||||
{ -0.6f, -0.4f, 1.f, 0.f, 0.f },
|
{ { -0.6f, -0.4f }, { 1.f, 0.f, 0.f } },
|
||||||
{ 0.6f, -0.4f, 0.f, 1.f, 0.f },
|
{ { 0.6f, -0.4f }, { 0.f, 1.f, 0.f } },
|
||||||
{ 0.f, 0.6f, 0.f, 0.f, 1.f }
|
{ { 0.f, 0.6f }, { 0.f, 0.f, 1.f } }
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char* vertex_shader_text =
|
static const char* vertex_shader_text =
|
||||||
@ -123,10 +126,10 @@ int main(void)
|
|||||||
|
|
||||||
glEnableVertexAttribArray(vpos_location);
|
glEnableVertexAttribArray(vpos_location);
|
||||||
glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE,
|
glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE,
|
||||||
sizeof(vertices[0]), (void*) 0);
|
sizeof(Vertex), (void*) offsetof(Vertex, pos));
|
||||||
glEnableVertexAttribArray(vcol_location);
|
glEnableVertexAttribArray(vcol_location);
|
||||||
glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE,
|
glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE,
|
||||||
sizeof(vertices[0]), (void*) (sizeof(float) * 2));
|
sizeof(Vertex), (void*) offsetof(Vertex, col));
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user