cleanup
This commit is contained in:
148
main.cc
148
main.cc
@@ -19,123 +19,6 @@
|
||||
#include "texture.hh"
|
||||
#include "objectParser.hh"
|
||||
|
||||
|
||||
const float cubeVertexData[][5] = {{0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f, 1.0f, 0.0f},
|
||||
{0.0f, 1.0f, 0.0f ,0.0f, 1.0f},
|
||||
{1.0f, 1.0f, 0.0f, 1.0f, 1.0f},
|
||||
|
||||
{1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, -1.0f, 1.0f, 0.0f},
|
||||
{1.0f, 1.0f, 0.0f, 0.0f, 1.0f},
|
||||
{1.0f, 1.0f, -1.0f, 1.0f, 1.0f},
|
||||
|
||||
{1.0f, 0.0f, -1.0f, 0.0f, 0.0f},
|
||||
{0.0f, 0.0f, -1.0f, 1.0f, 0.0f},
|
||||
{1.0f, 1.0f, -1.0f, 0.0f, 1.0f},
|
||||
{0.0f, 1.0f, -1.0f, 1.0f, 1.0f},
|
||||
|
||||
{0.0f, 0.0f, -1.0f, 0.0f, 0.0f},
|
||||
{0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
|
||||
{0.0f, 1.0f, -1.0f, 0.0f, 1.0f},
|
||||
{0.0f, 1.0f, 0.0f, 1.0f, 1.0f},
|
||||
|
||||
{0.0f, 0.0f, -1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, -1.0f, 1.0f, 0.0f},
|
||||
{0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
|
||||
{1.0f, 0.0f, 0.0f, 1.0f, 1.0f},
|
||||
|
||||
{0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
|
||||
{1.0f, 1.0f, 0.0f, 1.0f, 0.0f},
|
||||
{0.0f, 1.0f, -1.0f, 0.0f, 1.0f},
|
||||
{1.0f, 1.0f, -1.0f, 1.0f, 1.0f}};
|
||||
|
||||
const uint8_t cubeIndices[] = {0, 1, 2,
|
||||
1, 2, 3,
|
||||
|
||||
4, 5, 6,
|
||||
5, 6, 7,
|
||||
|
||||
8, 9, 10,
|
||||
9, 10, 11,
|
||||
|
||||
12, 13, 14,
|
||||
13, 14, 15,
|
||||
|
||||
16, 17, 18,
|
||||
17, 18, 19,
|
||||
|
||||
20, 21, 22,
|
||||
21, 22, 23};
|
||||
|
||||
const float vertices[][3] = {{0.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{0.0f, 1.0f, 0.0f},
|
||||
{1.0f, 1.0f, 0.0f},
|
||||
|
||||
{0.0f, 0.0f, -1.0f},
|
||||
{1.0f, 0.0f, -1.0f},
|
||||
{0.0f, 1.0f, -1.0f},
|
||||
{1.0f, 1.0f, -1.0f},
|
||||
|
||||
{-1.0f, -2.0f, -5.0f},
|
||||
{-1.5f, -1.0f, -4.5f},
|
||||
{-0.5f, -1.0f, -4.5f},
|
||||
{-1.0f, -1.0f, -5.5f}};
|
||||
|
||||
const float colors[][3] = {{1.0f, 0.0f, 1.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{0.0f, 1.0f, 0.0f},
|
||||
{0.0f, 0.0f, 1.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{0.0f, 1.0f, 0.0f},
|
||||
{0.0f, 0.0f, 1.0f},
|
||||
{1.0f, 0.0f, 1.0f},
|
||||
|
||||
{1.0f, 1.0f, 1.0f},
|
||||
{0.0f, 0.0f, 1.0f},
|
||||
{0.0f, 1.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f}};
|
||||
|
||||
const float texcoords[][2] = {{0.0f, 0.0f},
|
||||
{1.0f, 0.0f},
|
||||
{0.0f, 1.0f},
|
||||
{1.0f, 1.0f},
|
||||
|
||||
{1.0f, 1.0f},
|
||||
{1.0f, 0.0f},
|
||||
{0.0f, 1.0f},
|
||||
{0.0f, 0.0f},
|
||||
|
||||
{0.0f, 0.0f},
|
||||
{0.0f, 0.0f},
|
||||
{0.0f, 0.0f},
|
||||
{0.0f, 0.0f}};
|
||||
|
||||
const unsigned indices[] = {0, 2, 1,
|
||||
2, 3, 1,
|
||||
|
||||
0, 4, 1,
|
||||
1, 4, 5,
|
||||
|
||||
1, 7, 3,
|
||||
1, 5, 7,
|
||||
|
||||
2, 3, 7,
|
||||
2, 7, 6,
|
||||
|
||||
4, 6, 0,
|
||||
0, 6, 2,
|
||||
|
||||
4, 5, 6,
|
||||
5, 7, 6
|
||||
};
|
||||
|
||||
const unsigned indicesPyramid[] = {8, 10, 9,
|
||||
8, 11, 10,
|
||||
8, 9, 11,
|
||||
9, 10, 11};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
@@ -157,7 +40,6 @@ int main(int argc, char *argv[])
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
|
||||
//SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
@@ -239,7 +121,6 @@ int main(int argc, char *argv[])
|
||||
glUniform1i(prog.getUniformLocation("texBase"), 0);
|
||||
|
||||
int vertexAL = prog.getAttribLocation("vertex");
|
||||
//int vertexColorAL = prog.getAttribLocation("vertexColor");
|
||||
int vertexTCAL = prog.getAttribLocation("vertexTC");
|
||||
|
||||
checkGlError();
|
||||
@@ -249,33 +130,19 @@ int main(int argc, char *argv[])
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buf);
|
||||
checkGlError();
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*24*5, NULL, GL_STATIC_DRAW);
|
||||
//glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*24*5, (void*)cubeVertexData[0]);
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(objVertexAttribs)*std::get<0>(box).size(), NULL, GL_STATIC_DRAW);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(objVertexAttribs)*std::get<0>(box).size(),
|
||||
(void*)std::get<0>(box).data());
|
||||
|
||||
// glBufferData(GL_ARRAY_BUFFER, sizeof(float)*(2*3*12+2*12), NULL, GL_STATIC_DRAW);
|
||||
// glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*12, (void*)vertices[0]);
|
||||
// glBufferSubData(GL_ARRAY_BUFFER, sizeof(float)*3*12, sizeof(float)*3*12, (void*)colors[0]);
|
||||
// glBufferSubData(GL_ARRAY_BUFFER, sizeof(float)*2*3*12, sizeof(float)*2*12, (void*)texcoords[0]);
|
||||
|
||||
GLuint arr[2];
|
||||
glGenVertexArrays(2, arr);
|
||||
checkGlError();
|
||||
|
||||
// glBindVertexArray(arr[0]);
|
||||
// glEnableVertexAttribArray(vertexAL);
|
||||
// glEnableVertexAttribArray(vertexColorAL);
|
||||
// glEnableVertexAttribArray(vertexTCAL);
|
||||
// glVertexAttribPointer(vertexAL, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
// glVertexAttribPointer(vertexColorAL, 3, GL_FLOAT, GL_FALSE, 0, (void*)(sizeof(float)*3*12));
|
||||
// glVertexAttribPointer(vertexTCAL, 2, GL_FLOAT, GL_FALSE, 0, (void*)(sizeof(float)*2*3*12));
|
||||
|
||||
glBindVertexArray(arr[0]);
|
||||
glEnableVertexAttribArray(vertexAL);
|
||||
glEnableVertexAttribArray(vertexTCAL);
|
||||
glVertexAttribPointer(vertexAL, 3, GL_FLOAT, GL_FALSE, sizeof(objVertexAttribs), offsetof(objVertexAttribs, vertex));
|
||||
glVertexAttribPointer(vertexAL, 3, GL_FLOAT, GL_FALSE, sizeof(objVertexAttribs),
|
||||
(void*)offsetof(objVertexAttribs, vertex));
|
||||
glVertexAttribPointer(vertexTCAL, 2, GL_UNSIGNED_SHORT, GL_TRUE, sizeof(objVertexAttribs),
|
||||
(void*)offsetof(objVertexAttribs, texCoords));
|
||||
checkGlError();
|
||||
@@ -308,15 +175,9 @@ int main(int argc, char *argv[])
|
||||
glm::mat4 model = glm::rotate(SDL_GetTicks()*0.001f, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
glUniformMatrix4fv(prog.getUniformLocation("modelview_matrix"), 1, GL_FALSE,
|
||||
glm::value_ptr(view*model));
|
||||
// glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, indices);
|
||||
glDrawElements(GL_TRIANGLES, std::get<1>(box).size(), GL_UNSIGNED_SHORT, std::get<1>(box).data());
|
||||
checkGlError();
|
||||
|
||||
// glUniformMatrix4fv(prog.getUniformLocation("modelview_matrix"), 1, GL_FALSE,
|
||||
// glm::value_ptr(view));
|
||||
// glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_INT, indicesPyramid);
|
||||
// checkGlError();
|
||||
|
||||
|
||||
// glUseProgram(0);
|
||||
// sf::Time now = clock.getElapsedTime();
|
||||
// sf::Time elapsed = now - last;
|
||||
@@ -337,6 +198,7 @@ int main(int argc, char *argv[])
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
// Clean up
|
||||
IMG_Quit();
|
||||
SDL_Quit();
|
||||
|
||||
return retcode;
|
||||
|
||||
Reference in New Issue
Block a user