Last active
August 29, 2015 14:06
-
-
Save Sythelux/b122b3516b6c0042304e to your computer and use it in GitHub Desktop.
Vertex Arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* verticies Test,C++,OpenGL | |
* I have no rights on this ~Syd | |
*/ | |
typedef struct { | |
GLfloat x, y, z; | |
GLfloat r, g, b; | |
} Vertex; | |
const Vertex vertices[48] = { | |
0, 0, 0, 0, 0, 0, | |
30, 0, 0, 1, 0, 0, | |
30, 0, 10, 1, 0, 1, | |
0, 0, 10, 0, 0, 1, | |
0, 20, 0, 0, 1, 0, | |
30, 20, 0, 1, 1, 0, | |
30, 20, 10, 1, 1, 1, | |
0, 20, 10, 0, 1, 1 }; | |
static int indexCount = 24; | |
static const GLuint indices[24] = { | |
0, 1, 2, 3, | |
0, 3, 7, 4, | |
0, 4, 5, 1, | |
1, 2, 6, 5, | |
2, 3, 7, 6, | |
4, 5, 6, 7 | |
}; | |
void initVertexArray(void) { | |
glEnableClientState(GL_VERTEX_ARRAY); | |
glEnableClientState(GL_COLOR_ARRAY); | |
glVertexPointer(3, /* Komponenten pro Vertex (x,y,z) */ | |
GL_FLOAT, /* Typ der Komponenten */ | |
sizeof(Vertex), /* Offset zwischen 2 Vertizes im Array */ | |
&(vertices[0].x)); /* Zeiger auf die 1. Komponente */ | |
glColorPointer(3, GL_FLOAT, sizeof(Vertex), &(vertices[0].r)); | |
} | |
void drawVertexArray(void) { | |
glDrawElements(GL_QUADS, /* Primitivtyp */ | |
indexCount, /* Anzahl Indizes */ | |
GL_UNSIGNED_INT, /* Typ der Indizes */ | |
indices); /*Index-Array*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment