summaryrefslogtreecommitdiffstats
path: root/objloader.c
diff options
context:
space:
mode:
Diffstat (limited to 'objloader.c')
-rw-r--r--objloader.c53
1 files changed, 34 insertions, 19 deletions
diff --git a/objloader.c b/objloader.c
index 4c3548b..688c643 100644
--- a/objloader.c
+++ b/objloader.c
@@ -3,7 +3,6 @@
* kamilkss@gmail.com
*
* OBJ Loader
- * Look at line 194
*
* Code:
* http://www.gamedev.net/community/forums/topic.asp?topic_id=312335
@@ -13,7 +12,6 @@
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include "math3d.h"
-
#include "obj.h"
/* global */
@@ -32,7 +30,7 @@ static void resize(int w, int h)
glLoadIdentity();
/* produce the perspective projection */
- gluPerspective(40.0f, fAspect, 1.0, 40.0);
+ gluPerspective(60.0f, fAspect, 1.0, 40.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -41,7 +39,7 @@ static void resize(int w, int h)
SDL_SetVideoMode(w, h, 32, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_RESIZABLE);
}
-static void SetupRC()
+static void setup_opengl()
{
/* light values and coordinates */
GLfloat whiteLight[] = { 0.05f, 0.05f, 0.05f, 1.0f };
@@ -99,7 +97,7 @@ static void SetupRC()
}
/* process SDL events */
-void processEvents()
+void process_events()
{
SDL_Event event;
SDLKey sym;
@@ -139,13 +137,37 @@ static void draw_ground(void)
glEnd();
}
-void render()
+void render(ObjModel *model)
{
/* clear the window with current clearing color */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
draw_ground();
+
+ int i;
+
+ glPushMatrix();
+ glTranslatef(0.0f, -2.0f, -2.0f);
+ glScalef(0.2f, 0.2f, 0.2f);
+ glBegin(GL_QUADS);
+
+ for (i = 0; i < model->nFace; i++)
+ {
+ glNormal3f(model->NormalArray[model->FaceArray[i].Normal[0]].x, model->NormalArray[model->FaceArray[i].Normal[0]].y, model->NormalArray[model->FaceArray[i].Normal[0]].z );
+ glVertex3f(model->VertexArray[model->FaceArray[i].Vertex[0]].x, model->VertexArray[model->FaceArray[i].Vertex[0]].y, model->VertexArray[model->FaceArray[i].Vertex[0]].z );
+
+ glNormal3f(model->NormalArray[model->FaceArray[i].Normal[1]].x, model->NormalArray[model->FaceArray[i].Normal[1]].y, model->NormalArray[model->FaceArray[i].Normal[1]].z );
+ glVertex3f(model->VertexArray[model->FaceArray[i].Vertex[1]].x, model->VertexArray[model->FaceArray[i].Vertex[1]].y, model->VertexArray[model->FaceArray[i].Vertex[1]].z );
+
+ glNormal3f(model->NormalArray[model->FaceArray[i].Normal[2]].x, model->NormalArray[model->FaceArray[i].Normal[2]].y, model->NormalArray[model->FaceArray[i].Normal[2]].z );
+ glVertex3f(model->VertexArray[model->FaceArray[i].Vertex[2]].x, model->VertexArray[model->FaceArray[i].Vertex[2]].y, model->VertexArray[model->FaceArray[i].Vertex[2]].z );
+ glNormal3f(model->NormalArray[model->FaceArray[i].Normal[3]].x, model->NormalArray[model->FaceArray[i].Normal[3]].y, model->NormalArray[model->FaceArray[i].Normal[3]].z );
+ glVertex3f(model->VertexArray[model->FaceArray[i].Vertex[3]].x, model->VertexArray[model->FaceArray[i].Vertex[3]].y, model->VertexArray[model->FaceArray[i].Vertex[3]].z );
+
+ }
+ glEnd();
+ glPopMatrix();
+
/* buffer swap */
SDL_GL_SwapBuffers();
}
@@ -189,7 +211,7 @@ int main(void)
fprintf(stdout, "status: using GLEW %s\n", glewGetString(GLEW_VERSION));
/* setup few stuff before rendring */
- SetupRC();
+ setup_opengl();
/* OBJ Loading */
char *memory = NULL;
@@ -198,22 +220,15 @@ int main(void)
ObjModel *model = ObjLoadModel(memory, bytes);
printf("Object Model has: %d faces!\n", model->nFace);
- /* XXX: Insert Code Here */
-
-
/* main loop */
while (program_running)
{
- processEvents();
- render();
+ process_events();
+ render(model);
}
- /* might never be reached, meh */
- free(model->NormalArray);
- free(model->TexCoordArray);
- free(model->FaceArray);
- free(model->VertexArray);
- free(model);
+ /* free up the resources */
+ ObjFree(model);
puts("bye!");
return 0;