fix line endings on LogoBox sources

This commit is contained in:
Josh Holtrop 2011-10-11 12:12:28 -04:00
parent d556ef69bf
commit 4207934753
2 changed files with 162 additions and 162 deletions

View File

@ -1,137 +1,137 @@
/* /*
* Author: Josh Holtrop * Author: Josh Holtrop
* DornerWorks ScreenSaver * DornerWorks ScreenSaver
* This module can be used to create "LogoBox" objects * This module can be used to create "LogoBox" objects
* which consist of a 3D DW logo * which consist of a 3D DW logo
*/ */
#include <GL/gl.h> #include <GL/gl.h>
#include <iostream> #include <iostream>
#include "wfobj/WFObj.h" #include "wfobj/WFObj.h"
#include "LogoBox.h" #include "LogoBox.h"
#include "cfs.h" #include "cfs.h"
#include "glslUtil/glslUtil.h" #include "glslUtil/glslUtil.h"
#include "WFObjLoadFile.h" #include "WFObjLoadFile.h"
using namespace std; using namespace std;
static WFObj obj; static WFObj obj;
static GLuint program; static GLuint program;
static GLint ambient_loc, diffuse_loc, specular_loc, shininess_loc; static GLint ambient_loc, diffuse_loc, specular_loc, shininess_loc;
enum Locations { enum Locations {
LOC_POSITION, LOC_POSITION,
LOC_NORMAL LOC_NORMAL
}; };
static float _width, _depth, _height; static float _width, _depth, _height;
static bool loaded = false; static bool loaded = false;
/* /*
* construct a LogoBox object * construct a LogoBox object
* The first time the constructor is called it loads the * The first time the constructor is called it loads the
* Alias Wavefront object model. Subsequent calls will * Alias Wavefront object model. Subsequent calls will
* reuse the same module. * reuse the same module.
*/ */
LogoBox::LogoBox() LogoBox::LogoBox()
{ {
if (!loaded) if (!loaded)
{ {
if (obj.load("logo/dwlogo.obj", WFObjLoadFile)) if (obj.load("logo/dwlogo.obj", WFObjLoadFile))
{ {
const float * aabb = obj.getAABB(); const float * aabb = obj.getAABB();
float c_x = (aabb[0] + aabb[3]) / 2.0f; float c_x = (aabb[0] + aabb[3]) / 2.0f;
float c_y = (aabb[1] + aabb[4]) / 2.0f; float c_y = (aabb[1] + aabb[4]) / 2.0f;
float c_z = (aabb[2] + aabb[5]) / 2.0f; float c_z = (aabb[2] + aabb[5]) / 2.0f;
_width = aabb[3] - aabb[0]; _width = aabb[3] - aabb[0];
_depth = aabb[4] - aabb[1]; _depth = aabb[4] - aabb[1];
_height = aabb[5] - aabb[2]; _height = aabb[5] - aabb[2];
loaded = loadShaders(); loaded = loadShaders();
} }
else else
{ {
cerr << "Error loading dwlogo.obj" << endl; cerr << "Error loading dwlogo.obj" << endl;
} }
} }
m_width = _width; m_width = _width;
m_depth = _depth; m_depth = _depth;
m_height = _height; m_height = _height;
} }
bool LogoBox::loadShaders() bool LogoBox::loadShaders()
{ {
const guAttribBinding bindings[] = { const guAttribBinding bindings[] = {
{LOC_POSITION, "pos"}, {LOC_POSITION, "pos"},
{LOC_NORMAL, "normal"}, {LOC_NORMAL, "normal"},
{0, NULL} {0, NULL}
}; };
const char *v_shader_src = (const char *) getFile("shaders/obj.vp", NULL); const char *v_shader_src = (const char *) getFile("shaders/obj.vp", NULL);
const char *f_shader_src = (const char *) getFile("shaders/obj.fp", NULL); const char *f_shader_src = (const char *) getFile("shaders/obj.fp", NULL);
if (v_shader_src == NULL || f_shader_src == NULL) if (v_shader_src == NULL || f_shader_src == NULL)
{ {
cerr << "Error reading shader source files" << endl; cerr << "Error reading shader source files" << endl;
return false; return false;
} }
program = guMakeProgramFromSource(v_shader_src, f_shader_src, bindings); program = guMakeProgramFromSource(v_shader_src, f_shader_src, bindings);
if (program == 0) if (program == 0)
{ {
cerr << "Error creating shaders." << endl; cerr << "Error creating shaders." << endl;
return false; return false;
} }
ambient_loc = glGetUniformLocation(program, "ambient"); ambient_loc = glGetUniformLocation(program, "ambient");
diffuse_loc = glGetUniformLocation(program, "diffuse"); diffuse_loc = glGetUniformLocation(program, "diffuse");
specular_loc = glGetUniformLocation(program, "specular"); specular_loc = glGetUniformLocation(program, "specular");
shininess_loc = glGetUniformLocation(program, "shininess"); shininess_loc = glGetUniformLocation(program, "shininess");
glUseProgram(program); glUseProgram(program);
/* set up a default material */ /* set up a default material */
glUniform4f(ambient_loc, 0.2, 0.2, 0.2, 1.0); glUniform4f(ambient_loc, 0.2, 0.2, 0.2, 1.0);
glUniform4f(diffuse_loc, 1.0, 0.6, 0.0, 1.0); glUniform4f(diffuse_loc, 1.0, 0.6, 0.0, 1.0);
glUniform4f(specular_loc, 1.0, 1.0, 1.0, 1.0); glUniform4f(specular_loc, 1.0, 1.0, 1.0, 1.0);
glUniform1f(shininess_loc, 85.0); glUniform1f(shininess_loc, 85.0);
return true; return true;
} }
static void renderMaterial(const WFObj::Material & m) static void renderMaterial(const WFObj::Material & m)
{ {
if (m.flags & WFObj::Material::SHININESS_BIT) if (m.flags & WFObj::Material::SHININESS_BIT)
glUniform1f(shininess_loc, m.shininess); glUniform1f(shininess_loc, m.shininess);
if (m.flags & WFObj::Material::AMBIENT_BIT) if (m.flags & WFObj::Material::AMBIENT_BIT)
glUniform4fv(ambient_loc, 1, &m.ambient[0]); glUniform4fv(ambient_loc, 1, &m.ambient[0]);
if (m.flags & WFObj::Material::DIFFUSE_BIT) if (m.flags & WFObj::Material::DIFFUSE_BIT)
glUniform4fv(diffuse_loc, 1, &m.diffuse[0]); glUniform4fv(diffuse_loc, 1, &m.diffuse[0]);
if (m.flags & WFObj::Material::SPECULAR_BIT) if (m.flags & WFObj::Material::SPECULAR_BIT)
glUniform4fv(specular_loc, 1, &m.specular[0]); glUniform4fv(specular_loc, 1, &m.specular[0]);
if (m.flags & WFObj::Material::TEXTURE_BIT) if (m.flags & WFObj::Material::TEXTURE_BIT)
{ {
cerr << "error: textured materials not implemented yet" << endl; cerr << "error: textured materials not implemented yet" << endl;
} }
} }
void LogoBox::draw() void LogoBox::draw()
{ {
if (!loaded) if (!loaded)
return; return;
obj.bindBuffers(); obj.bindBuffers();
glUseProgram(program); glUseProgram(program);
glEnableVertexAttribArray(LOC_POSITION); glEnableVertexAttribArray(LOC_POSITION);
glEnableVertexAttribArray(LOC_NORMAL); glEnableVertexAttribArray(LOC_NORMAL);
int stride = obj.getStride(); int stride = obj.getStride();
glVertexAttribPointer(LOC_POSITION, 3, GL_FLOAT, GL_FALSE, glVertexAttribPointer(LOC_POSITION, 3, GL_FLOAT, GL_FALSE,
stride, (GLvoid *) obj.getVertexOffset()); stride, (GLvoid *) obj.getVertexOffset());
glVertexAttribPointer(LOC_NORMAL, 3, GL_FLOAT, GL_FALSE, glVertexAttribPointer(LOC_NORMAL, 3, GL_FLOAT, GL_FALSE,
stride, (GLvoid *) obj.getNormalOffset()); stride, (GLvoid *) obj.getNormalOffset());
for (map<string, WFObj::Material>::iterator it = obj.getMaterials().begin(); for (map<string, WFObj::Material>::iterator it = obj.getMaterials().begin();
it != obj.getMaterials().end(); it != obj.getMaterials().end();
it++) it++)
{ {
renderMaterial(it->second); renderMaterial(it->second);
glDrawElements(GL_TRIANGLES, it->second.num_vertices, glDrawElements(GL_TRIANGLES, it->second.num_vertices,
GL_UNSIGNED_SHORT, GL_UNSIGNED_SHORT,
(GLvoid *) (sizeof(GLushort) * it->second.first_vertex)); (GLvoid *) (sizeof(GLushort) * it->second.first_vertex));
} }
} }

View File

@ -1,25 +1,25 @@
/* /*
* Author: Josh Holtrop * Author: Josh Holtrop
* DornerWorks screensaver * DornerWorks screensaver
* The LogoBox class * The LogoBox class
*/ */
#ifndef LOGOBOX_H #ifndef LOGOBOX_H
#define LOGOBOX_H #define LOGOBOX_H
#include <GL/gl.h> #include <GL/gl.h>
class LogoBox class LogoBox
{ {
public: public:
LogoBox(); LogoBox();
void draw(); void draw();
float getWidth() const { return m_width; } float getWidth() const { return m_width; }
float getDepth() const { return m_depth; } float getDepth() const { return m_depth; }
float getHeight() const { return m_height; } float getHeight() const { return m_height; }
protected: protected:
bool loadShaders(); bool loadShaders();
float m_width, m_depth, m_height; float m_width, m_depth, m_height;
}; };
#endif #endif