|
|
@@ -24,6 +24,8 @@
|
|
|
#include "shaders.h"
|
|
|
#include "textures.h"
|
|
|
|
|
|
+#include "mesh.h"
|
|
|
+
|
|
|
#include "viking_math.h"
|
|
|
|
|
|
const int SCREEN_WIDTH = 640;
|
|
|
@@ -40,47 +42,38 @@ void close();
|
|
|
static ODIN_Window* window = 0;
|
|
|
|
|
|
|
|
|
+static const GLuint indices[36] = {
|
|
|
+ 0, 1, 2,
|
|
|
+ 3, 0, 4,
|
|
|
+ 5, 0, 6,
|
|
|
+ 3, 6, 0,
|
|
|
+ 0, 2, 4,
|
|
|
+ 5, 1, 0,
|
|
|
+ 2, 1, 5,
|
|
|
+ 7, 6, 3,
|
|
|
+ 6, 7, 5,
|
|
|
+ 7, 3, 4,
|
|
|
+ 7, 4, 2,
|
|
|
+ 7, 2, 5
|
|
|
+};
|
|
|
+
|
|
|
// Test OpenGL rendering
|
|
|
-static const GLfloat vertices[108] = {
|
|
|
- -1.0f,-1.0f,-1.0f, // triangle 1 : begin
|
|
|
- -1.0f,-1.0f, 1.0f,
|
|
|
- -1.0f, 1.0f, 1.0f, // triangle 1 : end
|
|
|
- 1.0f, 1.0f,-1.0f, // triangle 2 : begin
|
|
|
- -1.0f,-1.0f,-1.0f,
|
|
|
- -1.0f, 1.0f,-1.0f, // triangle 2 : end
|
|
|
- 1.0f,-1.0f, 1.0f,
|
|
|
- -1.0f,-1.0f,-1.0f,
|
|
|
- 1.0f,-1.0f,-1.0f,
|
|
|
- 1.0f, 1.0f,-1.0f,
|
|
|
- 1.0f,-1.0f,-1.0f,
|
|
|
- -1.0f,-1.0f,-1.0f,
|
|
|
- -1.0f,-1.0f,-1.0f,
|
|
|
- -1.0f, 1.0f, 1.0f,
|
|
|
- -1.0f, 1.0f,-1.0f,
|
|
|
- 1.0f,-1.0f, 1.0f,
|
|
|
- -1.0f,-1.0f, 1.0f,
|
|
|
- -1.0f,-1.0f,-1.0f,
|
|
|
- -1.0f, 1.0f, 1.0f,
|
|
|
- -1.0f,-1.0f, 1.0f,
|
|
|
- 1.0f,-1.0f, 1.0f,
|
|
|
- 1.0f, 1.0f, 1.0f,
|
|
|
- 1.0f,-1.0f,-1.0f,
|
|
|
- 1.0f, 1.0f,-1.0f,
|
|
|
- 1.0f,-1.0f,-1.0f,
|
|
|
- 1.0f, 1.0f, 1.0f,
|
|
|
- 1.0f,-1.0f, 1.0f,
|
|
|
- 1.0f, 1.0f, 1.0f,
|
|
|
- 1.0f, 1.0f,-1.0f,
|
|
|
- -1.0f, 1.0f,-1.0f,
|
|
|
- 1.0f, 1.0f, 1.0f,
|
|
|
- -1.0f, 1.0f,-1.0f,
|
|
|
- -1.0f, 1.0f, 1.0f,
|
|
|
- 1.0f, 1.0f, 1.0f,
|
|
|
- -1.0f, 1.0f, 1.0f,
|
|
|
- 1.0f,-1.0f, 1.0f
|
|
|
+static const GLfloat vertices[24] = {
|
|
|
+
|
|
|
+
|
|
|
+ -1.0f,-1.0f,-1.0f, // 0
|
|
|
+ -1.0f,-1.0f, 1.0f, // 1
|
|
|
+ -1.0f, 1.0f, 1.0f, // 2
|
|
|
+
|
|
|
+ 1.0f, 1.0f,-1.0f, // 3
|
|
|
+ -1.0f, 1.0f,-1.0f, // 4
|
|
|
+
|
|
|
+ 1.0f,-1.0f, 1.0f, // 5
|
|
|
+ 1.0f,-1.0f,-1.0f, // 6
|
|
|
+ 1.0f, 1.0f, 1.0f // 7
|
|
|
};
|
|
|
|
|
|
-static const GLfloat colors[108] = {
|
|
|
+static const GLfloat colors[24] = {
|
|
|
0.583f, 0.771f, 0.014f,
|
|
|
0.609f, 0.115f, 0.436f,
|
|
|
0.327f, 0.483f, 0.844f,
|
|
|
@@ -88,38 +81,10 @@ static const GLfloat colors[108] = {
|
|
|
0.435f, 0.602f, 0.223f,
|
|
|
0.310f, 0.747f, 0.185f,
|
|
|
0.597f, 0.770f, 0.761f,
|
|
|
- 0.559f, 0.436f, 0.730f,
|
|
|
- 0.359f, 0.583f, 0.152f,
|
|
|
- 0.483f, 0.596f, 0.789f,
|
|
|
- 0.559f, 0.861f, 0.639f,
|
|
|
- 0.195f, 0.548f, 0.859f,
|
|
|
- 0.014f, 0.184f, 0.576f,
|
|
|
- 0.771f, 0.328f, 0.970f,
|
|
|
- 0.406f, 0.615f, 0.116f,
|
|
|
- 0.676f, 0.977f, 0.133f,
|
|
|
- 0.971f, 0.572f, 0.833f,
|
|
|
- 0.140f, 0.616f, 0.489f,
|
|
|
- 0.997f, 0.513f, 0.064f,
|
|
|
- 0.945f, 0.719f, 0.592f,
|
|
|
- 0.543f, 0.021f, 0.978f,
|
|
|
- 0.279f, 0.317f, 0.505f,
|
|
|
- 0.167f, 0.620f, 0.077f,
|
|
|
- 0.347f, 0.857f, 0.137f,
|
|
|
- 0.055f, 0.953f, 0.042f,
|
|
|
- 0.714f, 0.505f, 0.345f,
|
|
|
- 0.783f, 0.290f, 0.734f,
|
|
|
- 0.722f, 0.645f, 0.174f,
|
|
|
- 0.302f, 0.455f, 0.848f,
|
|
|
- 0.225f, 0.587f, 0.040f,
|
|
|
- 0.517f, 0.713f, 0.338f,
|
|
|
- 0.053f, 0.959f, 0.120f,
|
|
|
- 0.393f, 0.621f, 0.362f,
|
|
|
- 0.673f, 0.211f, 0.457f,
|
|
|
- 0.820f, 0.883f, 0.371f,
|
|
|
- 0.982f, 0.099f, 0.879f
|
|
|
+ 0.559f, 0.436f, 0.730f
|
|
|
};
|
|
|
|
|
|
-static const GLfloat uvs[72] = {
|
|
|
+static const GLfloat uvs[16] = {
|
|
|
0.0f, 0.0f,
|
|
|
0.0f, -1.0f,
|
|
|
1.0f, 0.0f,
|
|
|
@@ -130,47 +95,8 @@ static const GLfloat uvs[72] = {
|
|
|
|
|
|
0.667979f, 1.0f-0.335851f,
|
|
|
0.336024f, 1.0f-0.671877f,
|
|
|
- 0.667969f, 1.0f-0.671889f,
|
|
|
-
|
|
|
- 1.000023f, 1.0f-0.000013f,
|
|
|
- 0.668104f, 1.0f-0.000013f,
|
|
|
- 0.667979f, 1.0f-0.335851f,
|
|
|
-
|
|
|
- 0.000059f, 1.0f-0.000004f,
|
|
|
- 0.335973f, 1.0f-0.335903f,
|
|
|
- 0.336098f, 1.0f-0.000071f,
|
|
|
-
|
|
|
- 0.667979f, 1.0f-0.335851f,
|
|
|
- 0.335973f, 1.0f-0.335903f,
|
|
|
- 0.336024f, 1.0f-0.671877f,
|
|
|
-
|
|
|
- 1.000004f, 1.0f-0.671847f,
|
|
|
- 0.999958f, 1.0f-0.336064f,
|
|
|
- 0.667979f, 1.0f-0.335851f,
|
|
|
-
|
|
|
- 0.668104f, 1.0f-0.000013f,
|
|
|
- 0.335973f, 1.0f-0.335903f,
|
|
|
- 0.667979f, 1.0f-0.335851f,
|
|
|
-
|
|
|
- 0.335973f, 1.0f-0.335903f,
|
|
|
- 0.668104f, 1.0f-0.000013f,
|
|
|
- 0.336098f, 1.0f-0.000071f,
|
|
|
-
|
|
|
- 0.000103f, 1.0f-0.336048f,
|
|
|
- 0.000004f, 1.0f-0.671870f,
|
|
|
- 0.336024f, 1.0f-0.671877f,
|
|
|
-
|
|
|
- 0.000103f, 1.0f-0.336048f,
|
|
|
- 0.336024f, 1.0f-0.671877f,
|
|
|
- 0.335973f, 1.0f-0.335903f,
|
|
|
-
|
|
|
- 0.667969f, 1.0f-0.671889f,
|
|
|
- 1.000004f, 1.0f-0.671847f,
|
|
|
- 0.667979f, 1.0f-0.335851f
|
|
|
};
|
|
|
|
|
|
-GLuint VaoID = 0;
|
|
|
-GLuint VboID = 0;
|
|
|
// End OpenGL rendering Test
|
|
|
|
|
|
// Function Declorations
|
|
|
@@ -471,23 +397,14 @@ int main(int argc, char* argv[]) {
|
|
|
// TEMP: Render test setup
|
|
|
printf("Starting gl triangle setup.\n");
|
|
|
|
|
|
- glGenVertexArrays(1, &VaoID);
|
|
|
- glBindVertexArray(VaoID);
|
|
|
-
|
|
|
- glGenBuffers(1, &VboID);
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, VboID);
|
|
|
- glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 108, vertices, GL_STATIC_DRAW);
|
|
|
-
|
|
|
- GLuint colorbuffer;
|
|
|
- glGenBuffers(1, &colorbuffer);
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, colorbuffer);
|
|
|
- glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 108, colors, GL_STATIC_DRAW);
|
|
|
-
|
|
|
- GLuint uvbuffer;
|
|
|
- glGenBuffers(1, &uvbuffer);
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
|
|
|
- glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 72, uvs, GL_STATIC_DRAW);
|
|
|
+
|
|
|
+ ODIN_Mesh* mesh = Mesh_newMesh();
|
|
|
+ Mesh_loadBufferData(mesh, 0, GL_ARRAY_BUFFER, GL_FLOAT, sizeof(GLfloat), 3, &vertices[0], 24);
|
|
|
+ Mesh_loadBufferData(mesh, 1, GL_ARRAY_BUFFER, GL_FLOAT, sizeof(GLfloat), 3, &colors[0], 24);
|
|
|
+ Mesh_loadBufferData(mesh, 2, GL_ARRAY_BUFFER, GL_FLOAT, sizeof(GLfloat), 2, &uvs[0], 16);
|
|
|
|
|
|
+ // Load the index buffer now
|
|
|
+ Mesh_loadIBOData(mesh, &indices[0], 36);
|
|
|
|
|
|
|
|
|
|
|
|
@@ -582,9 +499,11 @@ int main(int argc, char* argv[]) {
|
|
|
// OpenGL Rendering loop
|
|
|
Window_clearColor(100.0/255.0, 149.0/255.0, 237.0/255.0, 1.0);
|
|
|
|
|
|
+
|
|
|
glUseProgram(shaderTest->program_id);
|
|
|
glUniformMatrix4fv(MvpID, 1, GL_FALSE, mvp);
|
|
|
|
|
|
+ /*
|
|
|
// Render studd here?
|
|
|
glEnableVertexAttribArray(0);
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, VboID);
|
|
|
@@ -616,7 +535,14 @@ int main(int argc, char* argv[]) {
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 12*3);
|
|
|
glDisableVertexAttribArray(0);
|
|
|
-
|
|
|
+ */
|
|
|
+
|
|
|
+ // Bind mesh vao
|
|
|
+ Mesh_bindVao(mesh);
|
|
|
+
|
|
|
+ glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);
|
|
|
+
|
|
|
+ Mesh_unbindVao();
|
|
|
|
|
|
Window_swapBuffer(window);
|
|
|
|