From 4207934753cb7c68b4a10c8e15ec0f52b5a238f2 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 11 Oct 2011 12:12:28 -0400 Subject: [PATCH] fix line endings on LogoBox sources --- src/LogoBox.cc | 274 ++++++++++++++++++++++++------------------------- src/LogoBox.h | 50 ++++----- 2 files changed, 162 insertions(+), 162 deletions(-) diff --git a/src/LogoBox.cc b/src/LogoBox.cc index bdd8526..8319b8e 100644 --- a/src/LogoBox.cc +++ b/src/LogoBox.cc @@ -1,137 +1,137 @@ -/* - * Author: Josh Holtrop - * DornerWorks ScreenSaver - * This module can be used to create "LogoBox" objects - * which consist of a 3D DW logo - */ - -#include - -#include - -#include "wfobj/WFObj.h" -#include "LogoBox.h" -#include "cfs.h" -#include "glslUtil/glslUtil.h" -#include "WFObjLoadFile.h" - -using namespace std; - -static WFObj obj; -static GLuint program; -static GLint ambient_loc, diffuse_loc, specular_loc, shininess_loc; -enum Locations { - LOC_POSITION, - LOC_NORMAL -}; -static float _width, _depth, _height; -static bool loaded = false; - -/* - * construct a LogoBox object - * The first time the constructor is called it loads the - * Alias Wavefront object model. Subsequent calls will - * reuse the same module. - */ -LogoBox::LogoBox() -{ - if (!loaded) - { - if (obj.load("logo/dwlogo.obj", WFObjLoadFile)) - { - const float * aabb = obj.getAABB(); - - float c_x = (aabb[0] + aabb[3]) / 2.0f; - float c_y = (aabb[1] + aabb[4]) / 2.0f; - float c_z = (aabb[2] + aabb[5]) / 2.0f; - - _width = aabb[3] - aabb[0]; - _depth = aabb[4] - aabb[1]; - _height = aabb[5] - aabb[2]; - - loaded = loadShaders(); - } - else - { - cerr << "Error loading dwlogo.obj" << endl; - } - } - m_width = _width; - m_depth = _depth; - m_height = _height; -} - -bool LogoBox::loadShaders() -{ - const guAttribBinding bindings[] = { - {LOC_POSITION, "pos"}, - {LOC_NORMAL, "normal"}, - {0, 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); - if (v_shader_src == NULL || f_shader_src == NULL) - { - cerr << "Error reading shader source files" << endl; - return false; - } - program = guMakeProgramFromSource(v_shader_src, f_shader_src, bindings); - if (program == 0) - { - cerr << "Error creating shaders." << endl; - return false; - } - - ambient_loc = glGetUniformLocation(program, "ambient"); - diffuse_loc = glGetUniformLocation(program, "diffuse"); - specular_loc = glGetUniformLocation(program, "specular"); - shininess_loc = glGetUniformLocation(program, "shininess"); - - glUseProgram(program); - /* set up a default material */ - glUniform4f(ambient_loc, 0.2, 0.2, 0.2, 1.0); - glUniform4f(diffuse_loc, 1.0, 0.6, 0.0, 1.0); - glUniform4f(specular_loc, 1.0, 1.0, 1.0, 1.0); - glUniform1f(shininess_loc, 85.0); - return true; -} - -static void renderMaterial(const WFObj::Material & m) -{ - if (m.flags & WFObj::Material::SHININESS_BIT) - glUniform1f(shininess_loc, m.shininess); - if (m.flags & WFObj::Material::AMBIENT_BIT) - glUniform4fv(ambient_loc, 1, &m.ambient[0]); - if (m.flags & WFObj::Material::DIFFUSE_BIT) - glUniform4fv(diffuse_loc, 1, &m.diffuse[0]); - if (m.flags & WFObj::Material::SPECULAR_BIT) - glUniform4fv(specular_loc, 1, &m.specular[0]); - if (m.flags & WFObj::Material::TEXTURE_BIT) - { - cerr << "error: textured materials not implemented yet" << endl; - } -} - -void LogoBox::draw() -{ - if (!loaded) - return; - obj.bindBuffers(); - glUseProgram(program); - glEnableVertexAttribArray(LOC_POSITION); - glEnableVertexAttribArray(LOC_NORMAL); - int stride = obj.getStride(); - glVertexAttribPointer(LOC_POSITION, 3, GL_FLOAT, GL_FALSE, - stride, (GLvoid *) obj.getVertexOffset()); - glVertexAttribPointer(LOC_NORMAL, 3, GL_FLOAT, GL_FALSE, - stride, (GLvoid *) obj.getNormalOffset()); - for (map::iterator it = obj.getMaterials().begin(); - it != obj.getMaterials().end(); - it++) - { - renderMaterial(it->second); - glDrawElements(GL_TRIANGLES, it->second.num_vertices, - GL_UNSIGNED_SHORT, - (GLvoid *) (sizeof(GLushort) * it->second.first_vertex)); - } -} +/* + * Author: Josh Holtrop + * DornerWorks ScreenSaver + * This module can be used to create "LogoBox" objects + * which consist of a 3D DW logo + */ + +#include + +#include + +#include "wfobj/WFObj.h" +#include "LogoBox.h" +#include "cfs.h" +#include "glslUtil/glslUtil.h" +#include "WFObjLoadFile.h" + +using namespace std; + +static WFObj obj; +static GLuint program; +static GLint ambient_loc, diffuse_loc, specular_loc, shininess_loc; +enum Locations { + LOC_POSITION, + LOC_NORMAL +}; +static float _width, _depth, _height; +static bool loaded = false; + +/* + * construct a LogoBox object + * The first time the constructor is called it loads the + * Alias Wavefront object model. Subsequent calls will + * reuse the same module. + */ +LogoBox::LogoBox() +{ + if (!loaded) + { + if (obj.load("logo/dwlogo.obj", WFObjLoadFile)) + { + const float * aabb = obj.getAABB(); + + float c_x = (aabb[0] + aabb[3]) / 2.0f; + float c_y = (aabb[1] + aabb[4]) / 2.0f; + float c_z = (aabb[2] + aabb[5]) / 2.0f; + + _width = aabb[3] - aabb[0]; + _depth = aabb[4] - aabb[1]; + _height = aabb[5] - aabb[2]; + + loaded = loadShaders(); + } + else + { + cerr << "Error loading dwlogo.obj" << endl; + } + } + m_width = _width; + m_depth = _depth; + m_height = _height; +} + +bool LogoBox::loadShaders() +{ + const guAttribBinding bindings[] = { + {LOC_POSITION, "pos"}, + {LOC_NORMAL, "normal"}, + {0, 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); + if (v_shader_src == NULL || f_shader_src == NULL) + { + cerr << "Error reading shader source files" << endl; + return false; + } + program = guMakeProgramFromSource(v_shader_src, f_shader_src, bindings); + if (program == 0) + { + cerr << "Error creating shaders." << endl; + return false; + } + + ambient_loc = glGetUniformLocation(program, "ambient"); + diffuse_loc = glGetUniformLocation(program, "diffuse"); + specular_loc = glGetUniformLocation(program, "specular"); + shininess_loc = glGetUniformLocation(program, "shininess"); + + glUseProgram(program); + /* set up a default material */ + glUniform4f(ambient_loc, 0.2, 0.2, 0.2, 1.0); + glUniform4f(diffuse_loc, 1.0, 0.6, 0.0, 1.0); + glUniform4f(specular_loc, 1.0, 1.0, 1.0, 1.0); + glUniform1f(shininess_loc, 85.0); + return true; +} + +static void renderMaterial(const WFObj::Material & m) +{ + if (m.flags & WFObj::Material::SHININESS_BIT) + glUniform1f(shininess_loc, m.shininess); + if (m.flags & WFObj::Material::AMBIENT_BIT) + glUniform4fv(ambient_loc, 1, &m.ambient[0]); + if (m.flags & WFObj::Material::DIFFUSE_BIT) + glUniform4fv(diffuse_loc, 1, &m.diffuse[0]); + if (m.flags & WFObj::Material::SPECULAR_BIT) + glUniform4fv(specular_loc, 1, &m.specular[0]); + if (m.flags & WFObj::Material::TEXTURE_BIT) + { + cerr << "error: textured materials not implemented yet" << endl; + } +} + +void LogoBox::draw() +{ + if (!loaded) + return; + obj.bindBuffers(); + glUseProgram(program); + glEnableVertexAttribArray(LOC_POSITION); + glEnableVertexAttribArray(LOC_NORMAL); + int stride = obj.getStride(); + glVertexAttribPointer(LOC_POSITION, 3, GL_FLOAT, GL_FALSE, + stride, (GLvoid *) obj.getVertexOffset()); + glVertexAttribPointer(LOC_NORMAL, 3, GL_FLOAT, GL_FALSE, + stride, (GLvoid *) obj.getNormalOffset()); + for (map::iterator it = obj.getMaterials().begin(); + it != obj.getMaterials().end(); + it++) + { + renderMaterial(it->second); + glDrawElements(GL_TRIANGLES, it->second.num_vertices, + GL_UNSIGNED_SHORT, + (GLvoid *) (sizeof(GLushort) * it->second.first_vertex)); + } +} diff --git a/src/LogoBox.h b/src/LogoBox.h index 92f7b87..81461ce 100644 --- a/src/LogoBox.h +++ b/src/LogoBox.h @@ -1,25 +1,25 @@ -/* - * Author: Josh Holtrop - * DornerWorks screensaver - * The LogoBox class - */ - -#ifndef LOGOBOX_H -#define LOGOBOX_H - -#include - -class LogoBox -{ -public: - LogoBox(); - void draw(); - float getWidth() const { return m_width; } - float getDepth() const { return m_depth; } - float getHeight() const { return m_height; } -protected: - bool loadShaders(); - float m_width, m_depth, m_height; -}; - -#endif +/* + * Author: Josh Holtrop + * DornerWorks screensaver + * The LogoBox class + */ + +#ifndef LOGOBOX_H +#define LOGOBOX_H + +#include + +class LogoBox +{ +public: + LogoBox(); + void draw(); + float getWidth() const { return m_width; } + float getDepth() const { return m_depth; } + float getHeight() const { return m_height; } +protected: + bool loadShaders(); + float m_width, m_depth, m_height; +}; + +#endif