Permalink
Browse files

added shaders and glm stuff. Need to refactor models as Dustin suggested

  • Loading branch information...
1 parent 3304183 commit 06ec3ef58c62b0cc56eae5f172c9571ab25222ee @ChrisLundquist committed Nov 8, 2011
Showing with 401 additions and 152 deletions.
  1. +30 −25 Driver.cpp
  2. +5 −12 Model.cpp
  3. +8 −8 Model.h
  4. +140 −102 Obj.cpp
  5. +2 −4 Obj.h
  6. +1 −1 Ply.cpp
  7. +2 −0 Ply.h
  8. +165 −0 Shader.cpp
  9. +27 −0 Shader.h
  10. +8 −0 basic.frag
  11. +13 −0 basic.vert
View
@@ -6,6 +6,7 @@
#include <glm/glm.hpp>
#include "Model.h"
#include "Obj.h"
+#include "Shader.h"
Model::Obj m = Model::Obj();
@@ -14,30 +15,6 @@ void usage(){
std::cout << "Please specify paths to models" << std::endl;
}
-void reshape(GLint width, GLint height) {
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(65.0, (float)width / height, 1, 100);
- glMatrixMode(GL_MODELVIEW);
-}
-
-void keyboard(unsigned char key, int x, int y){
-
-}
-
-void display(void) {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- glTranslatef(0, 0, -6);
- glColor3f(1,1,1);
- m.draw();
- glutSwapBuffers();
- int i;
- if(i = glGetError())
- std::cerr << "OpenGL Error" << std::endl;
-}
-
void printGLError() {
GLenum fboStatus;
fboStatus = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
@@ -73,7 +50,7 @@ void printGLError() {
case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
error = "Framebuffer Incomplete Layer Targets";
- // Make sure the number of layers for each // attachment is the same break;
+ // Make sure the number of layers for each attachment is the same
break;
default:
error = "Unknown Error";
@@ -83,6 +60,31 @@ void printGLError() {
}
}
+void reshape(GLint width, GLint height) {
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ gluPerspective(65.0, (float)width / height, 1, 100);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+void keyboard(unsigned char key, int x, int y){
+
+}
+
+void display(void) {
+ static float f = 0.0f;
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+ glTranslatef(0, 0, -10);
+ glRotatef(f,1.0f,0.0f,0.0f);
+ glColor3f(1,1,1);
+ m.draw();
+ glutSwapBuffers();
+ printGLError();
+ f += 0.1f;
+}
+
int main(int argc, char** argv){
glutInit (&argc, argv);
@@ -96,11 +98,14 @@ int main(int argc, char** argv){
glutReshapeFunc (reshape);
glutKeyboardFunc (keyboard);
glutDisplayFunc (display);
+ glutIdleFunc(display);
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
+ Shader shader("basic.vert","basic.frag");
+ shader.bind();
printGLError();
/*
//TODO, parse argv to load a given model type then render it
View
@@ -1,13 +1,10 @@
#include "Model.h"
namespace Model {
Model::Model(){
- totalConnectedTriangles = 0;
- totalConnectedPoints = 0;
-
- vertices = new std::vector<float>();
- triangles = new std::vector<float>();
- normals = new std::vector<float>();
- textureCoordinates = new std::vector<float>();
+ vertices = std::vector<glm::vec3>();
+ triangles = std::vector<unsigned>();
+ normals = std::vector<glm::vec3>();
+ uvs = std::vector<glm::vec3>();
vaoID[0] = 0;
vboID[0] = 0;
}
@@ -16,7 +13,7 @@ namespace Model {
release();
}
- float* Model::calculateNormal(float* coord1, float* coord2, float* coord3){
+ float* Model::calculateNormal(float coord1[3], float coord2[3], float coord3[3]){
/* calculate Vector1 and Vector2 */
float va[3], vb[3], vr[3], val;
va[0] = coord1[0] - coord2[0];
@@ -45,9 +42,5 @@ namespace Model {
}
void Model::release(){
- delete vertices;
- delete triangles;
- delete normals;
- delete textureCoordinates;
}
}
View
16 Model.h
@@ -22,19 +22,19 @@ namespace Model {
class Model {
public:
Model();
+ Model(char* filename);
virtual ~Model();
-
- float* calculateNormal(float* coord1,float* coord2,float* coord3 );
+
+ // calculates the normal of a triangle
+ float* calculateNormal(float coord1[3],float coord2[3],float coord3[3] );
virtual bool load(char *filename) = 0;
virtual void release() = 0;
virtual void draw() = 0;
- std::vector<float>* normals;
- std::vector<float>* triangles;
- std::vector<float>* vertices;
- std::vector<float>* textureCoordinates;
- long totalConnectedPoints;
- long totalConnectedTriangles;
+ std::vector<glm::vec3> normals;
+ std::vector<unsigned> triangles;
+ std::vector<glm::vec3> vertices;
+ std::vector<glm::vec3> uvs;
unsigned vaoID[1];
unsigned vboID[1];
};
Oops, something went wrong.

0 comments on commit 06ec3ef

Please sign in to comment.