reorganize source a bit, building but not rendering LogoBoxes
This commit is contained in:
parent
00b9723aac
commit
55bf10c282
68
LogoBox.cc
68
LogoBox.cc
@ -1,68 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
* 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 "WFObj.h"
|
|
||||||
#include "LogoBox.h"
|
|
||||||
#include "LoadFile.h"
|
|
||||||
#include <string.h> /* memcpy() */
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
static GLuint _logoList = 0;
|
|
||||||
static GLuint _drawList;
|
|
||||||
static LoadFile loadFile;
|
|
||||||
static float _width, _depth, _height;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 (_logoList == 0)
|
|
||||||
{
|
|
||||||
WFObj obj(loadFile);
|
|
||||||
if (obj.load(FileLoader::Path("", "dwlogo.obj")))
|
|
||||||
{
|
|
||||||
_logoList = obj.render(false);
|
|
||||||
if (_logoList == 0)
|
|
||||||
{
|
|
||||||
cerr << "Error rendering dwlogo.obj" << endl;
|
|
||||||
}
|
|
||||||
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];
|
|
||||||
|
|
||||||
_drawList = glGenLists(1);
|
|
||||||
glNewList(_drawList, GL_COMPILE);
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(-c_x, -c_y, -c_z);
|
|
||||||
glCallList(_logoList);
|
|
||||||
glPopMatrix();
|
|
||||||
glEndList();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cerr << "Error loading dwlogo.obj" << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_drawList = _drawList;
|
|
||||||
m_width = _width;
|
|
||||||
m_depth = _depth;
|
|
||||||
m_height = _height;
|
|
||||||
}
|
|
11
SConstruct
11
SConstruct
@ -10,6 +10,7 @@ load_files = ['logo/dwlogo.obj', 'logo/dwlogo.mtl', Glob('shaders/*')]
|
|||||||
|
|
||||||
env = Environment(CPPPATH = ['.'])
|
env = Environment(CPPPATH = ['.'])
|
||||||
env.ParseConfig("pkg-config --cflags --libs glib-2.0 gdk-2.0 atk gtk+-2.0 gtkglext-1.0")
|
env.ParseConfig("pkg-config --cflags --libs glib-2.0 gdk-2.0 atk gtk+-2.0 gtkglext-1.0")
|
||||||
|
env.Append(CPPFLAGS = ['-Isrc', '-DGL_GLEXT_PROTOTYPES'])
|
||||||
|
|
||||||
# modes builder
|
# modes builder
|
||||||
|
|
||||||
@ -40,7 +41,15 @@ env.Append(BUILDERS = {'CFS' : Builder(action = CFS, emitter = CFS_emitter)})
|
|||||||
|
|
||||||
# source file list
|
# source file list
|
||||||
|
|
||||||
sources = [Glob('*.c'), Glob('*.cc'), Glob('LoadFile/*.cc'), Glob('modes/*.cc')]
|
sources = [
|
||||||
|
'cfs.cc',
|
||||||
|
Glob('src/*.c'),
|
||||||
|
Glob('src/*.cc'),
|
||||||
|
Glob('LoadFile/*.cc'),
|
||||||
|
Glob('modes/*.cc'),
|
||||||
|
Glob('wfobj/*.cc'),
|
||||||
|
Glob('glslUtil/*.c'),
|
||||||
|
]
|
||||||
|
|
||||||
env.CFS('cfs.cc', load_files)
|
env.CFS('cfs.cc', load_files)
|
||||||
env.Depends('cfs.cc', 'cfs_gen/cfs_gen.py')
|
env.Depends('cfs.cc', 'cfs_gen/cfs_gen.py')
|
||||||
|
39
shaders/obj.fp
Normal file
39
shaders/obj.fp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||||
|
precision highp float;
|
||||||
|
#else
|
||||||
|
precision mediump float;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uniform vec4 ambient, diffuse, specular;
|
||||||
|
uniform float shininess;
|
||||||
|
|
||||||
|
varying vec3 pos_i;
|
||||||
|
varying vec3 normal_i;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
vec3 n, lightDir;
|
||||||
|
vec4 color;
|
||||||
|
float NdotL, RdotEye;
|
||||||
|
|
||||||
|
lightDir = normalize(vec3(-0.4, 0, -0.9));
|
||||||
|
color = vec4(0.2, 0.2, 0.2, 1.0) * ambient; /* ambient light */
|
||||||
|
n = normalize(normal_i);
|
||||||
|
|
||||||
|
NdotL = max(dot(n, -lightDir), 0.0);
|
||||||
|
|
||||||
|
if (NdotL > 0.0)
|
||||||
|
{
|
||||||
|
/* diffuse component */
|
||||||
|
color += diffuse * NdotL;
|
||||||
|
/* specular component */
|
||||||
|
RdotEye = dot(normalize(-pos_i), normalize(reflect(-lightDir, n)));
|
||||||
|
if (RdotEye > 0.0)
|
||||||
|
{
|
||||||
|
color += clamp(specular * pow(RdotEye, shininess), 0.0, 1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gl_FragColor = color;
|
||||||
|
}
|
13
shaders/obj.vp
Normal file
13
shaders/obj.vp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
attribute vec3 pos;
|
||||||
|
attribute vec3 normal;
|
||||||
|
|
||||||
|
varying vec3 pos_i;
|
||||||
|
varying vec3 normal_i;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 1);
|
||||||
|
pos_i = gl_Position.xyz;
|
||||||
|
normal_i = gl_NormalMatrix * normal;
|
||||||
|
}
|
102
src/LogoBox.cc
Normal file
102
src/LogoBox.cc
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogoBox::draw()
|
||||||
|
{
|
||||||
|
if (!loaded)
|
||||||
|
return;
|
||||||
|
}
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Author: Josh Holtrop
|
* Author: Josh Holtrop
|
||||||
* DornerWorks screensaver
|
* DornerWorks screensaver
|
||||||
@ -14,12 +13,12 @@ class LogoBox
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LogoBox();
|
LogoBox();
|
||||||
void draw() { glCallList(m_drawList); }
|
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:
|
||||||
GLuint m_drawList;
|
bool loadShaders();
|
||||||
float m_width, m_depth, m_height;
|
float m_width, m_depth, m_height;
|
||||||
};
|
};
|
||||||
|
|
16
src/WFObjLoadFile.cc
Normal file
16
src/WFObjLoadFile.cc
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
#include <string.h> /* memcpy() */
|
||||||
|
|
||||||
|
#include "WFObjLoadFile.h"
|
||||||
|
#include "cfs.h"
|
||||||
|
|
||||||
|
bool WFObjLoadFile(const char *fname, WFObj::Buffer & buff)
|
||||||
|
{
|
||||||
|
unsigned int length;
|
||||||
|
const unsigned char *dat = getFile(fname, &length);
|
||||||
|
if (dat == NULL)
|
||||||
|
return false;
|
||||||
|
buff.alloc(length);
|
||||||
|
memcpy(buff.data, dat, length);
|
||||||
|
return true;
|
||||||
|
}
|
9
src/WFObjLoadFile.h
Normal file
9
src/WFObjLoadFile.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
#ifndef WFOBJLOADFILE_H
|
||||||
|
#define WFOBJLOADFILE_H
|
||||||
|
|
||||||
|
#include "wfobj/WFObj.h"
|
||||||
|
|
||||||
|
bool WFObjLoadFile(const char *fname, WFObj::Buffer & buff);
|
||||||
|
|
||||||
|
#endif /* WFOBJLOADFILE_H */
|
Loading…
x
Reference in New Issue
Block a user