1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
int main()
{
//start glfw
if (!glfwInit()) return -1;
//create window
window = glfwCreateWindow(WIDTH, HEIGHT, "A window", NULL, NULL);
if (window == NULL)
{
glfwTerminate();
return -1;
}
//use window
glfwMakeContextCurrent(window);
//ativa sincronizaĆ§Ć£o vertical
glfwSwapInterval(1);
FILE *file = fopen("Iron_Man.obj", "r");
if (file == NULL)
{
printf("Impossible to open the file !\n");
return false;
}
if (glewInit() != GLEW_OK) {
fprintf(stderr, "FALECEU!!!\n");
getchar();
glfwTerminate();
return -1;
}
//load .obj assume its correct
LoadModelVertex(file);
//load image assume its correct
Load_texture(image);
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * out_vertices.size(), &out_vertices[0], GL_TRIANGLES); //not sure what this does, i thought this sent the data of the arrays provided to the buffer, but my teacher made me think otherwise...
//set color to clear window with
glClearColor(0, 0, 0, 0);
//set clear depth default
glClearDepth(1);
//set clear stencil default
glClearStencil(0);
//position, facing,UP (test to see if it drew behind camera, black screen too)
//lookAt(*new vec3(0, 0, 0), *new vec3(0, 0, 1), *new vec3(0, 1, 0));
//screen management
display();
//release glfw stuff
glfwTerminate();
}
void display()
{
do
{
//clear stuff
glClear(GL_COLOR_BUFFER_BIT || GL_DEPTH_BUFFER_BIT);
//glBindVertexArray(VAO); I had a Vao but did nothing with it so?
draw();
//swap buffers bcs we using back/front buffer
glfwSwapBuffers(window);
//process events and return
glfwPollEvents();
} while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS &&glfwWindowShouldClose(window) == 0);
}
void draw()
{
//activate array for writing, and drawarrays() uses this
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
//location and format of data with coordinates of given array
glVertexPointer(out_vertices.size(), GL_FLOAT, 0, &out_vertices);
glVertexPointer(out_uvs.size(), GL_FLOAT, 0, &out_uvs);
glVertexPointer(out_normals.size(), GL_FLOAT, 0, &out_normals);
glDrawArrays(GL_TRIANGLES, 0, out_vertices.size());
//glDrawElements(GL_TRIANGLES, out_vertices.size(), GL_UNSIGNED_INT, (void *)0); both these two don't work(black screen)
//deactivate
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
printf("drew a frame\n");
}
|