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
* DornerWorks ScreenSaver
* This module can be used to create "LogoBox" objects
* which consist of a 3D DW logo
*/
#include <GL/gl.h>
#include <iostream>
#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<string, WFObj::Material>::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 <GL/gl.h>
#include <iostream>
#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<string, WFObj::Material>::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));
}
}

View File

@ -1,25 +1,25 @@
/*
* Author: Josh Holtrop
* DornerWorks screensaver
* The LogoBox class
*/
#ifndef LOGOBOX_H
#define LOGOBOX_H
#include <GL/gl.h>
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 <GL/gl.h>
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