diff --git a/include/Aluminum/MeshData.hpp b/include/Aluminum/MeshData.hpp index ca27101..26a7f43 100755 --- a/include/Aluminum/MeshData.hpp +++ b/include/Aluminum/MeshData.hpp @@ -5,269 +5,269 @@ namespace aluminum { - using glm::to_string; - using glm::ivec2; - using glm::ivec4; - using glm::vec2; - using glm::vec3; - using glm::vec4; - using glm::mat4; + using glm::to_string; + using glm::ivec2; + using glm::ivec4; + using glm::vec2; + using glm::vec3; + using glm::vec4; + using glm::mat4; - using std::vector; + using std::vector; - /// Stores buffers related to rendering graphical objects + /// Stores buffers related to rendering graphical objects - /// A mesh is a collection of buffers storing vertices, colors, indices, etc. - /// that define the geometry and coloring/shading of a graphical object. - class MeshData { - public: + /// A mesh is a collection of buffers storing vertices, colors, indices, etc. + /// that define the geometry and coloring/shading of a graphical object. + class MeshData { + public: - /* - typedef vec3 Vertex; - typedef vec3 Normal; - typedef vec4 Color; - typedef vec3 TexCoord; - typedef unsigned int Index; + /* + typedef vec3 Vertex; + typedef vec3 Normal; + typedef vec4 Color; + typedef vec3 TexCoord; + typedef unsigned int Index; - typedef vector Vertices; - typedef vector Normals; - typedef vector Colors; - typedef vector TexCoords; - typedef vector Indices; - */ + typedef vector Vertices; + typedef vector Normals; + typedef vector Colors; + typedef vector TexCoords; + typedef vector Indices; + */ - /* - MeshData(const MeshData& cpy) : - mVertices(cpy.mVertices), - mNormals(cpy.mNormals), - mColors(cpy.mColors), - mTexCoords(cpy.mTexCoords), - mIndices(cpy.mIndices), - mPrimitive(cpy.mPrimitive) - {} - */ + /* + MeshData(const MeshData& cpy) : + mVertices(cpy.mVertices), + mNormals(cpy.mNormals), + mColors(cpy.mColors), + mTexCoords(cpy.mTexCoords), + mIndices(cpy.mIndices), + mPrimitive(cpy.mPrimitive) + {} + */ - /// @param[out] min minimum corner of bounding box - /// @param[out] max maximum corner of bounding box + /// @param[out] min minimum corner of bounding box + /// @param[out] max maximum corner of bounding box - MeshData(); + MeshData(); - MeshData &create(); + MeshData &create(); - //MeshData& makeRectangle2(vec2 vLL, vec2 vUR, vec2 tcLL, vec2 tcUR); - //MeshData& makeRectangle2(vec3 v0, vec3 v1, vec3 v2, vec3 v3, vec3 t0, vec3 t1, vec3 t2, vec3 t3); + //MeshData& makeRectangle2(vec2 vLL, vec2 vUR, vec2 tcLL, vec2 tcUR); + //MeshData& makeRectangle2(vec3 v0, vec3 v1, vec3 v2, vec3 v3, vec3 t0, vec3 t1, vec3 t2, vec3 t3); - MeshData &reset(); + MeshData &reset(); - void getBounds(vec3 &min, vec3 &max) const; + void getBounds(vec3 &min, vec3 &max) const; - vec3 getCenter() const; + vec3 getCenter() const; - void addMesh(MeshData &m2); //agf + void addMesh(MeshData &m2); //agf - /// Scale all vertices to lie in [-1,1] - void unitize(bool proportional = true); + /// Scale all vertices to lie in [-1,1] + void unitize(bool proportional = true); - /// Scale all vertices - MeshData &scale(float x, float y, float z); + /// Scale all vertices + MeshData &scale(float x, float y, float z); - MeshData &scale(float s) { - return scale(s, s, s); - } + MeshData &scale(float s) { + return scale(s, s, s); + } - //template - //MeshData& scale(const Vec<3,T>& v){ return scale(v[0],v[1],v[2]); } - //template - MeshData &scale(const vec3 &v) { - return scale(v[0], v[1], v[2]); - } - //MeshData& scale(const vec3& v); + //template + //MeshData& scale(const Vec<3,T>& v){ return scale(v[0],v[1],v[2]); } + //template + MeshData &scale(const vec3 &v) { + return scale(v[0], v[1], v[2]); + } + //MeshData& scale(const vec3& v); - /// Translate all vertices - MeshData &translate(float x, float y, float z); + /// Translate all vertices + MeshData &translate(float x, float y, float z); - //template - //MeshData& translate(const Vec<3,T>& v){ return translate(v[0],v[1],v[2]); } - //template - MeshData &translate(const vec3 &v) { - return translate(v[0], v[1], v[2]); - } + //template + //MeshData& translate(const Vec<3,T>& v){ return translate(v[0],v[1],v[2]); } + //template + MeshData &translate(const vec3 &v) { + return translate(v[0], v[1], v[2]); + } - /// Transform vertices by projective transform matrix + /// Transform vertices by projective transform matrix - /// @param[in] m projective transform matrix - /// @param[in] begin beginning index of vertices - /// @param[in] end ending index of vertices, negative amount specify distance from one past last element - //template - //MeshData& transform(const Mat<4,T>& m, int begin=0, int end=-1); + /// @param[in] m projective transform matrix + /// @param[in] begin beginning index of vertices + /// @param[in] end ending index of vertices, negative amount specify distance from one past last element + //template + //MeshData& transform(const Mat<4,T>& m, int begin=0, int end=-1); - //MeshData& transform(const mat4& m, int begin=0, int end=-1); + //MeshData& transform(const mat4& m, int begin=0, int end=-1); - MeshData &transform(const mat4 &m, int begin, int end); + MeshData &transform(const mat4 &m, int begin, int end); - MeshData &transform(const mat4 &m, int begin); + MeshData &transform(const mat4 &m, int begin); - MeshData &transform(const mat4 &m); + MeshData &transform(const mat4 &m); - /// Invert direction of normals - void invertNormals(); + /// Invert direction of normals + void invertNormals(); - const vector &vertices() const { - return mVertices; - } + const vector &vertices() const { + return mVertices; + } - const vector &normals() const { - return mNormals; - } + const vector &normals() const { + return mNormals; + } - const vector &colors() const { - return mColors; - } + const vector &colors() const { + return mColors; + } - const vector &texCoords() const { - return mTexCoords; - } + const vector &texCoords() const { + return mTexCoords; + } - const vector &indices() const { - return mIndices; - } + const vector &indices() const { + return mIndices; + } - void index(unsigned int i) { - indices().push_back(i); - } + void index(unsigned int i) { + indices().push_back(i); + } - void index(const unsigned int *buf, int size) { - for (int i = 0; i < size; ++i) { - index(buf[i]); - } - } + void index(const unsigned int *buf, int size) { + for (int i = 0; i < size; ++i) { + index(buf[i]); + } + } - void color(float r, float g, float b, float a = 1.0) { - color(vec4(r, g, b, a)); - } + void color(float r, float g, float b, float a = 1.0) { + color(vec4(r, g, b, a)); + } - - - void color(const vec3 &v) { - color(v.r, v.g, v.b); - } - void color(const vec4 &v) { - colors().push_back(v); - } - void color(const vec4 *buf, int size) { - for (int i = 0; i < size; ++i) { - color(buf[i][0], buf[i][1], buf[i][2], buf[i][3]); - } - } + void color(const vec3 &v) { + color(v.r, v.g, v.b); + } - void color(const vec3 *buf, int size) { - for (int i = 0; i < size; ++i) { - color(buf[i][0], buf[i][1], buf[i][2], 1.0); - } - } + void color(const vec4 &v) { + colors().push_back(v); + } + void color(const vec4 *buf, int size) { + for (int i = 0; i < size; ++i) { + color(buf[i][0], buf[i][1], buf[i][2], buf[i][3]); + } + } - void normal(float x, float y, float z = 0.0) { - normal(vec3(x, y, z)); - } + void color(const vec3 *buf, int size) { + for (int i = 0; i < size; ++i) { + color(buf[i][0], buf[i][1], buf[i][2], 1.0); + } + } - void normal(const vec3 &v) { - normals().push_back(v); - } - void normal(const vec3 *buf, int size) { - for (int i = 0; i < size; ++i) { - normal(buf[i][0], buf[i][1], buf[i][2]); - } - } + void normal(float x, float y, float z = 0.0) { + normal(vec3(x, y, z)); + } - void texCoord(float u, float v, float w = 0.0) { - texCoord(vec3(u, v, w)); - } + void normal(const vec3 &v) { + normals().push_back(v); + } - void texCoord(const vec3 &v) { - texCoords().push_back(v); - } + void normal(const vec3 *buf, int size) { + for (int i = 0; i < size; ++i) { + normal(buf[i][0], buf[i][1], buf[i][2]); + } + } - void texCoord(const vec3 *buf, int size) { - for (int i = 0; i < size; ++i) { - texCoord(buf[i][0], buf[i][1], buf[i][2]); - } - } + void texCoord(float u, float v, float w = 0.0) { + texCoord(vec3(u, v, w)); + } - void vertex(float x, float y, float z = 0.0) { - vertex(vec3(x, y, z)); - } + void texCoord(const vec3 &v) { + texCoords().push_back(v); + } - void vertex(const vec3 &v) { - vertices().push_back(v); - } + void texCoord(const vec3 *buf, int size) { + for (int i = 0; i < size; ++i) { + texCoord(buf[i][0], buf[i][1], buf[i][2]); + } + } - void vertex(const vec3 *buf, int size) { - for (int i = 0; i < size; ++i) { - vertex(buf[i][0], buf[i][1], buf[i][2]); - } - } + void vertex(float x, float y, float z = 0.0) { + vertex(vec3(x, y, z)); + } + void vertex(const vec3 &v) { + vertices().push_back(v); + } + void vertex(const vec3 *buf, int size) { + for (int i = 0; i < size; ++i) { + vertex(buf[i][0], buf[i][1], buf[i][2]); + } + } - /// Get number of faces (assumes triangles or quads) - // int numFaces() const { return mIndices.size() / ( ( mPrimitive == Graphics::TRIANGLES ) ? 3 : 4 ); } - /// Get indices as triangles - // TriFace& indexAsTri(){ return (TriFace*) indices(); } - /// Get indices as quads - // QuadFace& indexAsQuad(){ return (QuadFace*) indices(); } - vector &vertices() { - return mVertices; - } - vector &normals() { - return mNormals; - } + /// Get number of faces (assumes triangles or quads) + // int numFaces() const { return mIndices.size() / ( ( mPrimitive == Graphics::TRIANGLES ) ? 3 : 4 ); } + /// Get indices as triangles + // TriFace& indexAsTri(){ return (TriFace*) indices(); } + /// Get indices as quads + // QuadFace& indexAsQuad(){ return (QuadFace*) indices(); } - vector &colors() { - return mColors; - } + vector &vertices() { + return mVertices; + } - vector &texCoords() { - return mTexCoords; - } + vector &normals() { + return mNormals; + } - vector &indices() { - return mIndices; - } + vector &colors() { + return mColors; + } - friend std::ostream& operator<<(std::ostream& Str, const MeshData& md) { + vector &texCoords() { + return mTexCoords; + } - for (size_t i = 0; i < md.vertices().size(); i++) { - Str << "vertex: " << glm::to_string(md.vertices()[i]) << " texcoord:" << glm::to_string(md.texCoords()[i]) << "\n"; - } + vector &indices() { + return mIndices; + } - return Str; - } + friend std::ostream& operator<<(std::ostream& Str, const MeshData& md) { + for (size_t i = 0; i < md.vertices().size(); i++) { + Str << "vertex: " << glm::to_string(md.vertices()[i]) << " texcoord:" << glm::to_string(md.texCoords()[i]) << "\n"; + } - //GLint id() {return vaoID;} - protected: + return Str; + } - // Only populated (size>0) buffers will be used - vector mVertices; - vector mNormals; - vector mColors; - vector mTexCoords; - vector mIndices; - int mPrimitive; + //GLint id() {return vaoID;} + protected: - //GLint vaoID; - }; + // Only populated (size>0) buffers will be used + vector mVertices; + vector mNormals; + vector mColors; + vector mTexCoords; + vector mIndices; + + int mPrimitive; + + //GLint vaoID; + }; } // al:: diff --git a/linux/FreeGlutGLView.cpp b/linux/FreeGlutGLView.cpp index 31424bd..28c2345 100755 --- a/linux/FreeGlutGLView.cpp +++ b/linux/FreeGlutGLView.cpp @@ -73,6 +73,8 @@ void moved(int x, int y ) { void keyboard(unsigned char key, int x, int y) { + renderer->keyboard(key,x,y); + switch(key) { case 27: @@ -93,6 +95,29 @@ void keyboard(unsigned char key, int x, int y) { printf("done pressing...\n"); } + +void specialkeys(int key, int x, int y) { + renderer->specialkeys(key,x,y); + + switch (key) { + + case GLUT_KEY_UP: + std::cout << "UP\n"; + break; + case GLUT_KEY_DOWN: + std::cout << "DOWN\n"; + break; + case GLUT_KEY_RIGHT: + std::cout << "RIGHT\n"; + break; + case GLUT_KEY_LEFT: + std::cout << "LEFT\n"; + break; + + } + +} + FreeGlutGLView* FreeGlutGLView::start(void* _renderer) { return FreeGlutGLView::start(_renderer, "allomin"); } @@ -135,6 +160,7 @@ FreeGlutGLView* FreeGlutGLView::start(void* _renderer, std::string name) { glutDisplayFunc(&display); glutReshapeFunc(&reshape); glutKeyboardFunc(&keyboard); + glutSpecialFunc(&specialkeys); glutMouseFunc(&pressed); glutMotionFunc(&dragged); glutPassiveMotionFunc(&moved); diff --git a/linux/RendererLinux.cpp b/linux/RendererLinux.cpp index dbd316f..0f4b789 100755 --- a/linux/RendererLinux.cpp +++ b/linux/RendererLinux.cpp @@ -64,6 +64,8 @@ void RendererLinux::mouseDragged(int px, int py) {} void RendererLinux::mouseDown(int px, int py) {} void RendererLinux::mouseUp(int px, int py) {} void RendererLinux::mouseMoved(int px, int py) {} +void RendererLinux::keyboard(unsigned char key, int x, int y) {} +void RendererLinux::specialkeys(int key, int x, int y) {} diff --git a/linux/RendererLinux.hpp b/linux/RendererLinux.hpp index f40fc5c..45207c5 100755 --- a/linux/RendererLinux.hpp +++ b/linux/RendererLinux.hpp @@ -15,6 +15,7 @@ class RendererLinux { //basic windowing void start(); void start(std::string name); + void start(std::string name, int x, int y, int w, int h); virtual void onCreate(); virtual void onFrame(); @@ -40,6 +41,8 @@ virtual void mouseDragged(int px, int py); virtual void mouseDown(int px, int py); virtual void mouseUp(int px, int py); virtual void mouseMoved(int px, int py); +virtual void keyboard(unsigned char key, int x, int y); +virtual void specialkeys(int key, int x, int y); diff --git a/linux/run.command b/linux/run.command index c5be3af..4219313 100755 --- a/linux/run.command +++ b/linux/run.command @@ -121,7 +121,7 @@ LINUX_DIR="$RUN_PATH" #COCOA="-isysroot /Applications/XCode.app/Contents/Developer/Platforms/MacLINUX.platform/Developer/SDKs/MacLINUX$LINUX_VERSION.sdk -mmacosx-version-min=$LINUX_VERSION -framework Cocoa -framework QuartzCore -framework OpenGL -framework AppKit -framework Foundation -framework AVFoundation -framework CoreMedia " -LINUX_LIBS=" -lglut -lGL -lm -lfreeimage" +LINUX_LIBS=" -lglut -lGL -lm -lfreeimage -lSDL -lSDL_image" OPTIONS="-O3 -Wreturn-type -Wformat -Wmissing-braces -Wparentheses -Wswitch -Wunused-variable -Wsign-compare -Wno-unknown-pragmas -Woverloaded-virtual" diff --git a/osx/examples/xcode-demos/week5d_OrderIndependentBlending/aluminum/WBOIT.mm b/osx/examples/xcode-demos/week5d_OrderIndependentBlending/aluminum/WBOIT.mm index ad17a22..6b75ae2 100644 --- a/osx/examples/xcode-demos/week5d_OrderIndependentBlending/aluminum/WBOIT.mm +++ b/osx/examples/xcode-demos/week5d_OrderIndependentBlending/aluminum/WBOIT.mm @@ -12,18 +12,18 @@ #include "Aluminum/FBO.hpp" -/* +/* This example is an implementation of Morgan McGuire's Weighted, Blended Order-Independent Transparency method, described on his blog at: -http://casual-effects.blogspot.com/2014/03/weighted-blended-order-independent.html as well in their Journal of Computer Graphics Techniques paper at: http://jcgt.org/published/0002/02/09/ + http://casual-effects.blogspot.com/2014/03/weighted-blended-order-independent.html as well in their Journal of Computer Graphics Techniques paper at: http://jcgt.org/published/0002/02/09/ This example (almost) matches the reference image at: http://1.bp.blogspot.com/-5O6KDtfG9ys/Ux3I49VvArI/AAAAAAAABcM/b1SXEfH0mh0/s1600/2014-03-10_001_blendedOIT2_r101_g3d_r4283.png */ using namespace aluminum; class WBOIT : public RendererOSX { - + public: - + //parameters changed by keyboard presses float divVal = 250.0; float powVal = 8.0; @@ -31,187 +31,187 @@ This example (almost) matches the reference image at: http://1.bp.blogspot.com/- float clearAmt = 0.75; float blendAmt = 0.45; float colorStrength = 0.95; - + bool autoRotate = false; float RX = -10.0; float RY = 15.0; float RZ = 0.0; - + //internal variables - + FBO fbo_mra; Texture t0, t1; - + ResourceHandler rh; Program finalProgram, blendPassProgram; GLint posLoc=0, texCoordLoc=1; - + MeshBuffer smallRect, clipRect; mat4 model, view, proj; - + Behavior rotateBehavior; - - + + void makeMulitpleRenderTargetFBO() { - + // Make an fbo with two render targets. //"The first render target must have at least RGBA16F precision and the second must have at least R8 precision" - + int fw = 1024; int fh = 1024; - + t0 = Texture(fw, fh, GL_RGBA16F, GL_RGBA, GL_FLOAT); //t0 = Texture(fw, fh, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE); - + t1 = Texture(fw, fh, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE); //t1 = Texture(fw, fh, GL_RGBA16F, GL_RGBA, GL_FLOAT); - - + + std::vector ts; ts.push_back(t0); ts.push_back(t1); - + fbo_mra.create(ts); } - - + + void onCreate() { - + makeMulitpleRenderTargetFBO(); - + rh.loadProgram(blendPassProgram, "blendpass", posLoc, -1, -1, -1); rh.loadProgram(finalProgram, "final", posLoc, -1, texCoordLoc, -1); - + smallRect.init(MeshUtils::makeRectangle(30.0, 30.0), posLoc, -1, -1, -1); clipRect.init(MeshUtils::makeClipRectangle(), posLoc, -1, texCoordLoc, -1); - + proj = glm::perspective(glm::radians(60.0f), float(width)/float(height), 0.1f, 200.0f); view = glm::lookAt(vec3(0.0,0.0,1.0), vec3(0,0,0), vec3(0,1,0) ); model = glm::mat4(); - + rotateBehavior = Behavior(now()).delay(100).length(10000).range(vec3(0.0, M_PI * 6, M_PI * 2)).looping(true).repeats(-1); - + } - - - + + + void onFrame(){ - + vec3 totals; - + if (autoRotate) { totals = rotateBehavior.tick(now()).totals(); } else { totals = vec3(glm::radians(RX), glm::radians(RY), glm::radians(RZ)); } - + mat4 rx = glm::rotate(totals.x, vec3(1.0f,0.0f,0.0f)); mat4 ry = glm::rotate(totals.y, vec3(0.0f,1.0f,0.0f)); mat4 rz = glm::rotate(totals.z, vec3(0.0f,0.0f,1.0f)); - + mat4 r = rx * ry * rz; - - + + glBindFramebuffer(GL_FRAMEBUFFER, 0); glClearColor(clearAmt,clearAmt,clearAmt,1.0); glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - - + + + fbo_mra.bind(); { - + // "Clear the first render target to vec4(0) and the second render target to 1 (using a pixel shader or glClearBuffer + glClear)"" - + glClearBufferfv(GL_COLOR, 0, ptr(vec4(0.f))); glClearBufferfv(GL_COLOR, 1, ptr(vec4(1.f))); - - + + glEnable(GL_BLEND); glBlendFunci(0, GL_ONE, GL_ONE); //blend for color attachment 0 glBlendFunci(1, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA); //blend for color attachment 1 - + blendPassProgram.bind(); { glUniformMatrix4fv(blendPassProgram.uniform("view"), 1, 0, ptr(view)); glUniformMatrix4fv(blendPassProgram.uniform("proj"), 1, 0, ptr(proj)); - + glUniform1f(blendPassProgram.uniform("divVal"), divVal); glUniform1f(blendPassProgram.uniform("powVal"), powVal); glUniform1i(blendPassProgram.uniform("zDepthOn"), zDepthOn); - - + + //1st rect - + glUniform4f(blendPassProgram.uniform("inColor"), colorStrength,0.0,0.0,blendAmt); glUniform1f(blendPassProgram.uniform("zval"), -70.0); - + model = glm::translate( vec3(-10.0,-10.0,-70.0) ) * r; - + glUniformMatrix4fv(blendPassProgram.uniform("model"), 1, 0, ptr(model)); - + smallRect.draw(); - - - + + + //2nd rect glUniform4f(blendPassProgram.uniform("inColor"), colorStrength, colorStrength,0.0,blendAmt); glUniform1f(blendPassProgram.uniform("zval"), -60.0); - + model = glm::translate(vec3(0.0,-5.0,-60.0)) * r; glUniformMatrix4fv(blendPassProgram.uniform("model"), 1, 0, ptr(model)); - + smallRect.draw(); - - + + //3rd rect glUniform4f(blendPassProgram.uniform("inColor"), 0.0f,0.0f,colorStrength,blendAmt); glUniform1f(blendPassProgram.uniform("zval"), -50.0); - + model = glm::translate(vec3(10.0,0.0,-50.0)) * r; glUniformMatrix4fv(blendPassProgram.uniform("model"), 1, 0, ptr(model)); - + smallRect.draw(); - - - - + + + + } blendPassProgram.unbind(); - + } fbo_mra.unbind(); - - + + //now back to normal render buffer - + glViewport(0, 0, width, height); - + glEnable(GL_BLEND); glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); - + finalProgram.bind(); { - + glUniform1i(finalProgram.uniform("tex0"), 0); glUniform1i(finalProgram.uniform("tex1"), 1); - + t0.bind(GL_TEXTURE0); t1.bind(GL_TEXTURE1); - + clipRect.draw(); - + t0.unbind(GL_TEXTURE0); t1.unbind(GL_TEXTURE1); } finalProgram.unbind(); - + } - - + + void onReshape() { glViewport(0, 0, width, height); proj = glm::perspective(glm::radians(60.0f), float(width)/float(height), 0.1f, 200.0f); } - - + + virtual void keyDown(char key) { - + switch(key) { case kVK_ANSI_A : divVal += 1.0; @@ -243,16 +243,16 @@ virtual void keyDown(char key) { case kVK_ANSI_B : colorStrength -= 0.01; break; - + case kVK_ANSI_R : autoRotate = !autoRotate; break; - + case kVK_Space : zDepthOn = !zDepthOn; break; - - + + case kVK_ANSI_Y : RX += 0.5; break; @@ -272,25 +272,25 @@ virtual void keyDown(char key) { RZ -= 0.5; break; - - + + } - - - + + + cout << "divVal = " << divVal << "\n"; cout << "powVal = " << powVal << "\n"; cout << "zDepthOn = " << zDepthOn << "\n"; cout << "clearAmt = " << clearAmt << "\n"; cout << "blendAmt = " << blendAmt << "\n"; cout << "colorStrength = " << colorStrength << "\n"; - + cout << "rx / ry / rz = " << RX << " / " << RY << " / RZ \n"; - + } - - + + }; diff --git a/src/Aluminum/FBO.cpp b/src/Aluminum/FBO.cpp index 6f78137..307c53c 100755 --- a/src/Aluminum/FBO.cpp +++ b/src/Aluminum/FBO.cpp @@ -6,17 +6,17 @@ #endif namespace aluminum { - + /////////////////////////////////////////////////////////////////////////////// // convert OpenGL 3.2 core profile's internal format enum to string /////////////////////////////////////////////////////////////////////////////// std::string convertInternalFormatToString(GLenum format) { std::string formatName; - + switch (format) { //Table 3.12: sized internal color formats #ifndef BUILD_IOS - + case GL_R8: formatName = "GL_R8"; break; @@ -131,7 +131,7 @@ namespace aluminum { case GL_R8UI: formatName = "GL_R8UI"; break; - + case GL_R16I: formatName = "GL_R16I"; break; @@ -195,14 +195,14 @@ namespace aluminum { case GL_RGBA32UI: formatName = "GL_RGBA32UI"; break; - + case GL_RGBA4: formatName = "GL_RGBA4"; break; case GL_RGB5_A1: formatName = "GL_RGB5_A1"; break; - + //Table 3.13: sized interal depth formats case GL_DEPTH_COMPONENT16: formatName = "GL_DEPTH_COMPONENT16"; @@ -222,7 +222,7 @@ namespace aluminum { case GL_DEPTH32F_STENCIL8: formatName = "GL_DEPTH32F_STENCIL8"; break; - + //Table 4.10: sized internal formats for formats that can only be used with renderbuffers case GL_STENCIL_INDEX1: formatName = "GL_STENCIL_INDEX1"; @@ -236,7 +236,7 @@ namespace aluminum { case GL_STENCIL_INDEX16: formatName = "GL_STENCIL_INDEX16"; break; - + //Table 3.3: pixel data formats (these are not actually internal formats...) case GL_STENCIL_INDEX: formatName = "GL_STENCIL_INDEX"; @@ -300,11 +300,11 @@ namespace aluminum { formatName = "Unknown Format"; break; } - + return formatName; } - - + + /////////////////////////////////////////////////////////////////////////////// // return texture parameters as string using glGetTexLevelParameteriv() /////////////////////////////////////////////////////////////////////////////// @@ -312,7 +312,7 @@ namespace aluminum { #ifndef BUILD_IOS if (glIsTexture(id) == GL_FALSE) return "Not texture object"; - + int width, height, format; std::string formatName; glBindTexture(GL_TEXTURE_2D, id); @@ -320,27 +320,27 @@ namespace aluminum { glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); // get texture height glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format); // get texture internal format glBindTexture(GL_TEXTURE_2D, 0); - + formatName = convertInternalFormatToString(format); - + std::stringstream ss; ss << width << "x" << height << ", " << formatName << "(" << format << ")"; - + return ss.str(); #else return "not supported in IOS OpenGLES2.0"; #endif } - - - + + + /////////////////////////////////////////////////////////////////////////////// // return renderbuffer parameters as string using glGetRenderbufferParameteriv /////////////////////////////////////////////////////////////////////////////// std::string getRenderbufferParameters(GLuint id) { if (glIsRenderbuffer(id) == GL_FALSE) return "Not Renderbuffer object"; - + int width, height, format; std::string formatName; glBindRenderbuffer(GL_RENDERBUFFER, id); @@ -348,27 +348,27 @@ namespace aluminum { glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height); // get renderbuffer height glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_INTERNAL_FORMAT, &format); // get renderbuffer internal format glBindRenderbuffer(GL_RENDERBUFFER, 0); - + formatName = convertInternalFormatToString(format); - + std::stringstream ss; ss << width << "x" << height << ", " << formatName << "(" << format << ")"; return ss.str(); } - - + + void printFramebufferInfo() { #ifndef BUILD_IOS std::cout << "\n===== FBO STATUS =====\n"; - + // print max # of colorbuffers supported by FBO int colorBufferCount = 0; glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &colorBufferCount); std::cout << "Max Number of Color Buffer Attachment Points: " << colorBufferCount << std::endl; - + int objectType; int objectId; - + // print info of the colorbuffer attachable image for (int i = 0; i < colorBufferCount; ++i) { glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, @@ -380,9 +380,9 @@ namespace aluminum { GL_COLOR_ATTACHMENT0+ i, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &objectId); - + std::string formatName; - + std::cout << "Color Attachment " << i << ": "; if (objectType == GL_TEXTURE) { std::cout << "GL_TEXTURE, " << getTextureParameters(objectId) << std::endl; @@ -392,7 +392,7 @@ namespace aluminum { } } } - + // print info of the depthbuffer attachable image glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, @@ -403,7 +403,7 @@ namespace aluminum { GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &objectId); - + std::cout << "Depth Attachment: "; switch (objectType) { case GL_TEXTURE: @@ -414,7 +414,7 @@ namespace aluminum { break; } } - + // print info of the stencilbuffer attachable image glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, @@ -425,7 +425,7 @@ namespace aluminum { GL_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &objectId); - + std::cout << "Stencil Attachment: "; switch (objectType) { case GL_TEXTURE: @@ -436,50 +436,50 @@ namespace aluminum { break; } } - + std::cout << std::endl; #endif } - - + + FBO::FBO() { use = false; } - + FBO &FBO::create() { glGenFramebuffers(1, &fboID); return *this; } - - + + #ifdef BUILD_IOS FBO& FBO::create(int w, int h) { glGenFramebuffers(1, &fboID); return attach(Texture(w, h, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE), RBO(w, h, GL_DEPTH_COMPONENT16)); } #else - - + + FBO &FBO::create(int w, int h) { glGenFramebuffers(1, &fboID); return attach(Texture(w, h, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE), RBO(w, h, GL_DEPTH_COMPONENT24)); // return attach(Texture(w, h, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE), RBO(w, h, GL_DEPTH_COMPONENT32F)); } - + #endif - - + + FBO &FBO::create(Texture t) { glGenFramebuffers(1, &fboID); return attach(t); } - + FBO &FBO::create(Texture t, RBO rb) { glGenFramebuffers(1, &fboID); return attach(t, rb); } - - + + // Creates an FBO with multiple render targets. Assumes that the targets are 2D, the same size, and have no attached depth texture. FBO &FBO::create(std::vector ts) { glGenFramebuffers(1, &fboID); @@ -489,25 +489,23 @@ namespace aluminum { std::cerr << "In FBO : Can't create a multirender target with no textures! " << std::endl; exit(0); } - + //assuming sizes of all targets is the same width = ts[0].width; height = ts[1].height; - /*const int buff_size = ts.size(); - GLenum draw_buffers[buff_size];*/ - // Had to make this change in order to accomodate c++11, which does not allow you to - //GLenum* draw_buffers = (GLenum*)alloca(sizeof(GLenum)*ts.size()); + // Had to make this change in order to accomodate c++11, which does not allow you to allocate an array with a non-constant value. GLenum* draw_buffers = new GLenum[ts.size()]; for (int i = 0; i < ts.size(); i++) { - + glBindTexture(GL_TEXTURE_2D, ts[i].id()); glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, ts[i].id(), 0); draw_buffers[i] = GL_COLOR_ATTACHMENT0 + i; } - + glDrawBuffers((GLsizei)ts.size(), draw_buffers); + delete draw_buffers; //test FBO glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboID); @@ -516,179 +514,179 @@ namespace aluminum { printf("There is a problem with the multiple render target FBO\n"); exit(0); } - + //return to normal glBindFramebuffer(GL_FRAMEBUFFER, 0); - - + + return *this; //return attach(ts[0]); } - - - - + + + + FBO &FBO::replace(Texture t, RBO rb) { //delete old, and attach new texture.destroy(); rbo.destroy(); return attach(t, rb); } - + FBO &FBO::attach(Texture t, RBO rb) { - - + + #ifdef BUILD_IOS - + texture = t; rbo = rb; width = texture.width; height = texture.height; - + //1. bind FBO glBindFramebuffer(GL_FRAMEBUFFER, fboID); { - + //2. attach texture (as color attachment) to fbo texture.bind(); { glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER_APPLE, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.id(), 0); // glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.id(), 0); - + } texture.unbind(); - - + + /* //3. attach renderbuffer (as depth attachment) to fbo rb.bind(); { glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_APPLE, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb.id()); } rb.unbind(); */ - + checkStatus(); - + //4. unbind FBO } glBindFramebuffer(GL_FRAMEBUFFER, 0); - + return *this; #else - - + + texture = t; rbo = rb; width = texture.width; height = texture.height; - + //1. bind FBO glBindFramebuffer(GL_FRAMEBUFFER, fboID); { - + //2. attach texture (as color attachment) to fbo texture.bind(); { glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.id(), 0); } texture.unbind(); - + //3. attach renderbuffer (as depth attachment) to fbo rb.bind(); { glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb.id()); } rb.unbind(); - + checkStatus(); - + //4. unbind FBO } glBindFramebuffer(GL_FRAMEBUFFER, 0); - + return *this; #endif } - - + + FBO &FBO::replace(Texture t) { texture.destroy(); return attach(t); } - + #ifdef BUILD_IOS FBO& FBO::attach(Texture t) { - + texture = t; width = texture.width; height = texture.height; - + //1. bind FBO glBindFramebuffer(GL_FRAMEBUFFER, fboID); { - + //2. attach texture (as color attachment) to fbo texture.bind(); { glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER_APPLE, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.id(), 0); } texture.unbind(); - + checkStatus(); - + //3. unbind FBO } glBindFramebuffer(GL_FRAMEBUFFER, 0); - + return *this; } - + #else - + FBO &FBO::attach(Texture t) { - + texture = t; width = texture.width; height = texture.height; - + //1. bind FBO glBindFramebuffer(GL_FRAMEBUFFER, fboID); { - + //2. attach texture (as color attachment) to fbo texture.bind(); { glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.id(), 0); } texture.unbind(); - + checkStatus(); - + //3. unbind FBO } glBindFramebuffer(GL_FRAMEBUFFER, 0); - + return *this; } - + #endif - + void FBO::checkStatus() { /* assumes that the FBO is bound */ - + //printFramebufferInfo(); - + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { printf("in FBO : ERROR!!!!: Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER)); exit(0); } } - + //use this one if you are changing the fbo texture.. FBO &FBO::bind(Texture t) { attach(t); glViewport(0, 0, width, height); //w & h MUST match the texture size return *this; } - + //use this one if you are changing the fbo texture or rbo.. FBO &FBO::bind(Texture t, RBO rb) { attach(t, rb); glViewport(0, 0, width, height); //w & h MUST match the texture size return *this; } - + FBO &FBO::bind() { //printf("binding to fbo id = %d\n", fboID); // printf("fbo w/h = %d/%d\n", width, height); @@ -697,22 +695,22 @@ namespace aluminum { glViewport(0, 0, width, height); //w & h SHOULD match the texture size return *this; } - + FBO &FBO::unbind() { glBindFramebuffer(GL_FRAMEBUFFER, 0); return *this; } - + void FBO::unbindAll() { glBindFramebuffer(GL_FRAMEBUFFER, 0); - + } - - + + RBO::RBO() { use = false; } - + RBO::RBO(int _width, int _height, GLenum _format) { use = false; width = _width; @@ -720,7 +718,7 @@ namespace aluminum { internalformat = _format; create(); } - + RBO &RBO::create() { glGenRenderbuffers(1, &rboID); bind(); @@ -728,28 +726,28 @@ namespace aluminum { glRenderbufferStorage(GL_RENDERBUFFER, internalformat, width, height); } unbind(); - + return *this; } - + void RBO::destroy() { glDeleteRenderbuffers(1, &rboID); } - - + + GLint RBO::id() { return rboID; } - + RBO &RBO::bind() { glBindRenderbuffer(GL_RENDERBUFFER, rboID); return *this; } - + RBO &RBO::unbind() { glBindRenderbuffer(GL_RENDERBUFFER, 0); return *this; } - + }; diff --git a/src/Aluminum/MeshUtils.cpp b/src/Aluminum/MeshUtils.cpp index dea1200..d144c16 100755 --- a/src/Aluminum/MeshUtils.cpp +++ b/src/Aluminum/MeshUtils.cpp @@ -534,14 +534,14 @@ namespace aluminum { } - + void MeshUtils::addPoint(MeshData &m, vec3 v) { - + const vec3 vs[] = { v }; unsigned int off = (unsigned int) m.indices().size(); - + const unsigned int indices[] = { off }; - + m.vertex(vs, 1); m.index(indices, 1); } @@ -630,7 +630,7 @@ namespace aluminum { cout << "v1 : " << to_string(vs[1]) << "\n"; cout << "v2 : " << to_string(vs[2]) << "\n"; cout << "v3 : " << to_string(vs[3]) << "\n"; - + cout << "n0 : " << to_string(ns[0]) << "\n"; cout << "n1 : " << to_string(ns[1]) << "\n"; cout << "n2 : " << to_string(ns[2]) << "\n"; diff --git a/windows/examples/vs-demos/aluminum/BasicColor.cpp b/windows/examples/vs-demos/aluminum/BasicColor.cpp index 7f6dad3..2576bae 100644 --- a/windows/examples/vs-demos/aluminum/BasicColor.cpp +++ b/windows/examples/vs-demos/aluminum/BasicColor.cpp @@ -162,8 +162,8 @@ class Basic : public RendererWin32 { //examples of how to react to a key event - void keyDown(char key, bool shift, bool control, bool command, bool option, bool function) { - printf("in Basic: key = %c, shift=%d, control=%d, command=%d, option=%d, function=%d\n", key, shift, control, command, option, function); + void keyboard(unsigned char key, int x, int y) { + //printf("in Basic: key = %c, shift=%d, control=%d, command=%d, option=%d, function=%d\n", key, shift, control, command, option, function); switch (key) { case 'a': diff --git a/windows/examples/vs-demos/aluminum/Billboarding.cpp b/windows/examples/vs-demos/aluminum/Billboarding.cpp index 87076f3..851a601 100644 --- a/windows/examples/vs-demos/aluminum/Billboarding.cpp +++ b/windows/examples/vs-demos/aluminum/Billboarding.cpp @@ -71,7 +71,7 @@ class Billboarding : public RendererWin32 { Utils::randomSeed(); MeshData points; - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 1; i++) { MeshUtils::addPoint(points, Utils::randomVec3(-1.0,1.0), Utils::randomVec3(0.0,1.0)); } @@ -119,8 +119,11 @@ class Billboarding : public RendererWin32 { glViewport(0, 0, width, height); } + void mouseMoved(int x, int y){ + camera.rotateY(glm::radians(-2.)); + } - void keyDown(char key, bool shift, bool control, bool command, bool option, bool function) { + /*void keyboard(unsigned char key, int x, int y) { switch(key) { case ' ' : @@ -175,6 +178,6 @@ class Billboarding : public RendererWin32 { camera.translateY(-0.5); break; } - } + }*/ }; diff --git a/windows/examples/vs-demos/aluminum/ImageProcessing.cpp b/windows/examples/vs-demos/aluminum/ImageProcessing.cpp index 5c77027..28daaac 100644 --- a/windows/examples/vs-demos/aluminum/ImageProcessing.cpp +++ b/windows/examples/vs-demos/aluminum/ImageProcessing.cpp @@ -100,7 +100,7 @@ class ImageProcessing : public RendererWin32 { gamma = ((float)px/(float)width) * 5.0; } - void keyDown(char key, bool shift, bool control, bool command, bool option, bool function) { + void keyboard(unsigned char key, int x, int y) { switch(key) { case 'r' : diff --git a/windows/examples/vs-demos/aluminum/Main.cpp b/windows/examples/vs-demos/aluminum/Main.cpp index e6c3373..fbdcc97 100644 --- a/windows/examples/vs-demos/aluminum/Main.cpp +++ b/windows/examples/vs-demos/aluminum/Main.cpp @@ -21,14 +21,14 @@ int main() { //Lighting().start("Aluminum: Week3a Lighting", 400, 300); //FBOExample().start("Aluminum: Week3b FBOExample", 400, 300); //Cellular().start("Aluminum: Week3c Cellular", 400, 300); - //VertexDisplacement().start("Aluminum: Week4a VertexDisplacement", 400, 300); // <-- Buggy!! + //VertexDisplacement().start("Aluminum: Week4a VertexDisplacement", 400, 300); // <-- Less Buggy!! //ModelFromObjFile().start("Aluminum: Week4b ModelFromObjFile", 400, 300); - //NoiseSphere().start("Aluminum: Week5a NoiseSphere", 400, 300); // <-- Buggy!! + //NoiseSphere().start("Aluminum: Week5a NoiseSphere", 400, 300); //SkyBox().start("Aluminum: Week5b SkyBox", 400, 300); // <-- Buggy!! - //MiniPlanet().start("Aluminum: Week5c MiniPlanet", 400, 300); // <-- Buggy!! - //WBOIT().start("Aluminum: Week5d WBOIT", 400, 300); // <-- Buggy!! + MiniPlanet().start("Aluminum: Week5c MiniPlanet", 400, 300); // <-- Buggy!! + //WBOIT().start("Aluminum: Week5d WBOIT", 400, 300); //ImageProcessing().start("Aluminum: Week6a ImageProcessing", 400, 300); // <-- Buggy!! - //Billboarding().start("Aluminum: Week6b Billboarding", 400, 300); // <-- Buggy!! + //Billboarding().start("Aluminum: Week6b Billboarding", 400, 300); // <-- less Buggy!! return 0; } \ No newline at end of file diff --git a/windows/examples/vs-demos/aluminum/MiniPlanet.cpp b/windows/examples/vs-demos/aluminum/MiniPlanet.cpp index 5055c92..b7e3607 100644 --- a/windows/examples/vs-demos/aluminum/MiniPlanet.cpp +++ b/windows/examples/vs-demos/aluminum/MiniPlanet.cpp @@ -83,7 +83,7 @@ class MiniPlanet : public RendererWin32 { } - void keyDown(char key, bool shift, bool control, bool command, bool option, bool function) { + void keyboard(unsigned char key, int x, int y) { switch(key) { case ' ' : //reset diff --git a/windows/examples/vs-demos/aluminum/ModelFromObjFile.cpp b/windows/examples/vs-demos/aluminum/ModelFromObjFile.cpp index 786fa49..d40ba2f 100644 --- a/windows/examples/vs-demos/aluminum/ModelFromObjFile.cpp +++ b/windows/examples/vs-demos/aluminum/ModelFromObjFile.cpp @@ -100,7 +100,7 @@ class ModelFromObjFile : public RendererWin32 { modely = -1.2; cameraz = 4; - proj = glm::perspective(45.0f, (float)width/(float)height, 0.1f, 1000.0f); + proj = glm::perspective(glm::radians(45.0f), (float)width/(float)height, 0.1f, 1000.0f); view = glm::lookAt(vec3(camerax, cameray, -cameraz), vec3(0,0,0), vec3(0,1,0) ); model = glm::mat4(); model = glm::translate(model, vec3(modelx, modely, modelz)); @@ -145,7 +145,7 @@ class ModelFromObjFile : public RendererWin32 { - void keyDown(char key, bool shift, bool control, bool command, bool option, bool function) { + void keyboard(unsigned char key, int x, int y) { switch(key) { case ' ' : diff --git a/windows/examples/vs-demos/aluminum/SkyBox.cpp b/windows/examples/vs-demos/aluminum/SkyBox.cpp index 9a7bcfa..7186bfb 100644 --- a/windows/examples/vs-demos/aluminum/SkyBox.cpp +++ b/windows/examples/vs-demos/aluminum/SkyBox.cpp @@ -144,7 +144,7 @@ class SkyBox : public RendererWin32 { } - void keyDown(char key, bool shift, bool control, bool command, bool option, bool function) { + void keyboard(unsigned char key, int x, int y) { switch(key) { case ' ' : @@ -152,18 +152,22 @@ class SkyBox : public RendererWin32 { break; case 'a' : + printf("you pressed the A key!"); camera.rotateY(glm::radians(2.)); break; case 'd' : + printf("you pressed the D key!"); camera.rotateY(glm::radians(-2.)); break; case 'w' : + printf("you pressed the W key!"); camera.rotateX(glm::radians(2.)); break; case 'x' : + printf("you pressed the W key!"); camera.rotateX(glm::radians(-2.)); break; diff --git a/windows/examples/vs-demos/aluminum/VertexDisplacement.cpp b/windows/examples/vs-demos/aluminum/VertexDisplacement.cpp index 4edb45b..57b6e49 100644 --- a/windows/examples/vs-demos/aluminum/VertexDisplacement.cpp +++ b/windows/examples/vs-demos/aluminum/VertexDisplacement.cpp @@ -73,17 +73,19 @@ class VertexDisplacement : public RendererWin32 { void draw(mat4 proj, mat4 view) { //update times - t1 += 0.05 * t1dir; + //t1 += 0.00000005 * t1dir; + t1 = 0.0000000001; if (abs(t1) > 17.0) { t1dir *= -1; } - t2 += 0.07 * t2dir; + //t2 += 0.00000007 * t2dir; + t2 = 0.0000000002; if (abs(t2) > 23.0) { t2dir *= -1; } //rotate our model around the y-axis - vec3 totals = rotateBehavior.tick(now()).totals(); + vec3 totals = glm::radians(rotateBehavior.tick(now()).totals()); model1 = glm::mat4(); - model1 = glm::rotate(model1, totals.y, vec3(0.0f,1.0f,0.0f)); + //model1 = glm::rotate(model1, totals.y, vec3(0.0f,1.0f,0.0f)); //update colors diff --git a/windows/examples/vs-demos/aluminum/WBOIT.cpp b/windows/examples/vs-demos/aluminum/WBOIT.cpp index 20a6659..96681f8 100644 --- a/windows/examples/vs-demos/aluminum/WBOIT.cpp +++ b/windows/examples/vs-demos/aluminum/WBOIT.cpp @@ -211,7 +211,7 @@ class WBOIT : public RendererWin32 { } - void keyDown(char key, bool shift, bool control, bool command, bool option, bool function) { + void keyboard(unsigned char key, int x, int y) { switch(key) { case 'a' : diff --git a/windows/examples/vs-demos/vs-demos.sln b/windows/examples/vs-demos/vs-demos.sln index 33fcb10..a55523f 100644 --- a/windows/examples/vs-demos/vs-demos.sln +++ b/windows/examples/vs-demos/vs-demos.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 VisualStudioVersion = 12.0.21005.1 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vs-demos", "vs-demos.vcxproj", "{C6472734-9A1F-4F1D-A206-483C00EE08D9}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vs-demos", "aluminum\vs-demos.vcxproj", "{C6472734-9A1F-4F1D-A206-483C00EE08D9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/windows/include/Aluminum/Includes.hpp b/windows/include/Aluminum/Includes.hpp index 333a726..4192dee 100644 --- a/windows/include/Aluminum/Includes.hpp +++ b/windows/include/Aluminum/Includes.hpp @@ -10,7 +10,7 @@ #include -//#define GLM_FORCE_RADIANS // To get GLM to shutup +#define GLM_FORCE_RADIANS // To get GLM to shutup #include #pragma comment(lib, "glew32.lib") #define GLEW_STATIC diff --git a/windows/include/Aluminum/RendererWin32.hpp b/windows/include/Aluminum/RendererWin32.hpp index c326ef8..c4d30f8 100644 --- a/windows/include/Aluminum/RendererWin32.hpp +++ b/windows/include/Aluminum/RendererWin32.hpp @@ -37,6 +37,8 @@ namespace aluminum { virtual void keyboard(unsigned char key, int x, int y); protected: + GLuint _glVaoID; + private: }; } diff --git a/windows/include/Aluminum/ResourceHandler.hpp b/windows/include/Aluminum/ResourceHandler.hpp index 0aefe10..f26b15a 100644 --- a/windows/include/Aluminum/ResourceHandler.hpp +++ b/windows/include/Aluminum/ResourceHandler.hpp @@ -5,18 +5,25 @@ namespace aluminum { - class ResourceHandler { + class ResourceHandler { - public: - ResourceHandler(); + public: + ResourceHandler(); - //const char *contentsOfFile(std::string &file); - std::string contentsOfFile(std::string &file); - std::string pathToResource(const std::string &resource); - std::string pathToResource(const std::string &resource, const std::string &type); - void loadProgram(Program &p, const std::string &name, int pLoc, int nLoc, int tcLoc, int cLoc); - void loadTexture(Texture &t, const std::string &name); - }; + //const char *contentsOfFile(std::string &file); + std::string contentsOfFile(std::string &file); + std::string pathToResource(const std::string &resource); + std::string pathToResource(const std::string &resource, const std::string &type); + void loadProgram(Program &p, const std::string &name, int pLoc, int nLoc, int tcLoc, int cLoc); + void loadTexture(Texture &t, const std::string &name); + void loadImageData(GLubyte *data, const std::string &name); + void loadCubeMapTexture(Texture &t, int w, int h, const std::string &negz, + const std::string &posz, + const std::string &posy, + const std::string &negy, + const std::string &negx, + const std::string &posx); + }; } diff --git a/windows/src/Aluminum/FreeGlutGLView.cpp b/windows/src/Aluminum/FreeGlutGLView.cpp index 6744b04..57948b4 100644 --- a/windows/src/Aluminum/FreeGlutGLView.cpp +++ b/windows/src/Aluminum/FreeGlutGLView.cpp @@ -111,7 +111,7 @@ namespace aluminum { } FreeGlutGLView* FreeGlutGLView::start(void* _renderer, std::string name) { - return FreeGlutGLView::start(_renderer, "allomin", 200, 200); + return FreeGlutGLView::start(_renderer, "allomin", 400, 300); } FreeGlutGLView* FreeGlutGLView::start(void* _renderer, std::string name, int _width, int _height) { diff --git a/windows/src/Aluminum/RendererWin32.cpp b/windows/src/Aluminum/RendererWin32.cpp index 29b357b..8552946 100644 --- a/windows/src/Aluminum/RendererWin32.cpp +++ b/windows/src/Aluminum/RendererWin32.cpp @@ -24,7 +24,7 @@ namespace aluminum { void RendererWin32::start(std::string name, int _width, int _height) { printf("in RendererWin32::start(name)\n"); - FreeGlutGLView::start(this, name); + FreeGlutGLView::start(this, name, _width, _height); } diff --git a/windows/src/Aluminum/ResourceHandler.cpp b/windows/src/Aluminum/ResourceHandler.cpp index 11e83fb..268dfea 100644 --- a/windows/src/Aluminum/ResourceHandler.cpp +++ b/windows/src/Aluminum/ResourceHandler.cpp @@ -1,145 +1,284 @@ #include "Aluminum/ResourceHandler.hpp" +#include +#include +#include +#include +void PrintFullPath(const char * partialPath) +{ + char full[_MAX_PATH]; + if (_fullpath(full, partialPath, _MAX_PATH) != NULL) + printf("Full path is: %s\n", full); + else + printf("Invalid path\n"); +} + +//int main(void) +//{ +// PrintFullPath("test"); +// PrintFullPath("\\test"); +// PrintFullPath("..\\test"); +//} namespace aluminum { - - - ResourceHandler::ResourceHandler() { } - - std::string ResourceHandler::contentsOfFile(std::string &filename) { - std::cout << filename.c_str() << " " << filename << std::endl; - std::ifstream file; - file.open(filename.c_str()); - - if (!file) { - printf("in ResourceHander::contentsOfFile : error, couldn't find file!\n"); - exit(0); - } - - std::stringstream stream; - stream << file.rdbuf(); - file.close(); - - return stream.str(); - } - - string ResourceHandler::pathToResource(const std::string &resource) { return "implement me!"; } - - string ResourceHandler::pathToResource(const std::string &resource, const std::string &type) { - string result = resource + "." + type; - std::cout << result << std::endl; - return result; - } - - void ResourceHandler::loadProgram(Program &p, const std::string &name, int pLoc, int nLoc, int tcLoc, int cLoc) { - - p.create(); - - //string sv = pathToResource(name, "vsh"); // uncomment when it works - string sv = name + ".vsh"; - p.attach(contentsOfFile(sv), GL_VERTEX_SHADER); - - if (pLoc >= 0) glBindAttribLocation(p.id(), pLoc, "vertexPosition"); - if (nLoc >= 0) glBindAttribLocation(p.id(), nLoc, "vertexNormal"); - if (tcLoc >= 0) glBindAttribLocation(p.id(), tcLoc, "vertexTexCoord"); - if (cLoc >= 0) glBindAttribLocation(p.id(), cLoc, "vertexColor"); - - //string sp = pathToResource(name, "fsh"); // uncomment when it works - string sp = name +".fsh"; - p.attach(contentsOfFile(sp), GL_FRAGMENT_SHADER); - p.link(); - } - - void ResourceHandler::loadTexture(Texture &t, const std::string &name) { - - FreeImage_Initialise(); // Need this call to ensure FreeImage works... - - const char *filename = name.c_str(); - FREE_IMAGE_FORMAT format = FIF_UNKNOWN; - FIBITMAP *dib(0); - BYTE *bits(0); - unsigned int width(0), height(0), pixSz(0); - FREE_IMAGE_COLOR_TYPE colorf; - FREE_IMAGE_TYPE typef; - GLenum pixFormat = GL_RGBA; - - //check the file signature and deduce its format - format = FreeImage_GetFileType(filename, 0); - //if still unknown, try to guess the file format from the file extension - if (format == FIF_UNKNOWN) - format = FreeImage_GetFIFFromFilename(filename); - //if still unkown, return failure - if (format == FIF_UNKNOWN) { - printf("Unable to load file, exiting.."); - exit(1); - } - - //check that the plugin has reading capabilities and load the file - if (FreeImage_FIFSupportsReading(format)) - dib = FreeImage_Load(format, filename); - //if the image failed to load, return failure - if (!dib) { - printf("Image failed to load, exiting.."); - exit(1); - } - - - bits = FreeImage_GetBits(dib); - width = FreeImage_GetWidth(dib); - height = FreeImage_GetHeight(dib); - typef = FreeImage_GetImageType(dib); - colorf = FreeImage_GetColorType(dib); - pixSz = FreeImage_GetBPP(dib); - - switch (colorf) { - case FIC_MINISBLACK: - //right now this is a special case for different types of FONT textures... - //converting single channel to rgba so shaders are the same... - //prob should be in its own font loader class, not a general texture loading method - printf("FIC_MINISBLACK\n"); - pixFormat = GL_RED; - //dib = FreeImage_ConvertTo32Bits(dib); - //pixFormat = GL_RGBA; - break; - case FIC_MINISWHITE: - printf("FIC_MINISWHITE\n"); - break; - case FIC_PALETTE: - printf("FIC_PALETTE\n"); - break; - case FIC_CMYK: - printf("FIC_CMYK\n"); - break; - case FIC_RGB: - printf("FIC_RGB\n"); - pixFormat = GL_BGR; - //dib = FreeImage_ConvertTo32Bits(dib); - //pixFormat = GL_RGB; - break; - case FIC_RGBALPHA: - printf("FIC_RGBA\n"); - pixFormat = GL_RGBA; - break; - default: - printf("format %d not handled!\n", colorf); - break; - } - - //probably want to have a single channel format plus a single+alpha - - printf("format = %d\n", format); - printf("Image type = %d\n", typef); - printf("w/h = %d/%d\n", width, height); - printf("pixel bit size: %d\n", pixSz); - printf("FreeImage_IsTransparent = %d\n", FreeImage_IsTransparent(dib)); - printf("FreeImage_FlipHorizontal = %d\n", FreeImage_FlipHorizontal(dib)); - - GLubyte* data = (GLubyte*)malloc((width * height * 3)); - memcpy((GLubyte*)data, (GLubyte*)bits, width * height * 3); - - t = Texture(data, width, height, GL_RGBA, pixFormat, GL_UNSIGNED_BYTE); - FreeImage_Unload(dib); - - } - + + + ResourceHandler::ResourceHandler() { } + + std::string ResourceHandler::contentsOfFile(std::string &filename) { + std::cout << filename.c_str() << " " << filename << std::endl; + std::ifstream file; + file.open(filename.c_str()); + PrintFullPath(filename.c_str()); + if (!file) { + printf("in ResourceHander::contentsOfFile : error, couldn't find file!\n"); + //exit(0); + } + + std::stringstream stream; + stream << file.rdbuf(); + file.close(); + + return stream.str(); + } + + string ResourceHandler::pathToResource(const std::string &resource) { return resource; } + + string ResourceHandler::pathToResource(const std::string &resource, const std::string &type) { + string result = resource + "." + type; + std::cout << result << std::endl; + return result; + } + + void ResourceHandler::loadProgram(Program &p, const std::string &name, int pLoc, int nLoc, int tcLoc, int cLoc) { + + p.create(); + + //string sv = pathToResource(name, "vsh"); // uncomment when it works + string sv = name + ".vsh"; + p.attach(contentsOfFile(sv), GL_VERTEX_SHADER); + + if (pLoc >= 0) glBindAttribLocation(p.id(), pLoc, "vertexPosition"); + if (nLoc >= 0) glBindAttribLocation(p.id(), nLoc, "vertexNormal"); + if (tcLoc >= 0) glBindAttribLocation(p.id(), tcLoc, "vertexTexCoord"); + if (cLoc >= 0) glBindAttribLocation(p.id(), cLoc, "vertexColor"); + + //string sp = pathToResource(name, "fsh"); // uncomment when it works + string sp = name +".fsh"; + p.attach(contentsOfFile(sp), GL_FRAGMENT_SHADER); + p.link(); + } + + + void ResourceHandler::loadImageData(GLubyte *data, const std::string &name){ + FreeImage_Initialise(); // Need this call to ensure FreeImage works... + printf("loadImageData: %s", name.c_str()); + const char *filename = name.c_str(); + FREE_IMAGE_FORMAT format = FIF_UNKNOWN; + FIBITMAP *dib(0); + BYTE *bits(0); + unsigned int width(0), height(0), pixSz(0); + FREE_IMAGE_COLOR_TYPE colorf; + FREE_IMAGE_TYPE typef; + GLenum pixFormat = GL_RGBA; + + //check the file signature and deduce its format + format = FreeImage_GetFileType(filename, 0); + //if still unknown, try to guess the file format from the file extension + if (format == FIF_UNKNOWN) + format = FreeImage_GetFIFFromFilename(filename); + //if still unkown, return failure + if (format == FIF_UNKNOWN) { + printf("Unable to load file, exiting.."); + exit(1); + } + + //check that the plugin has reading capabilities and load the file + if (FreeImage_FIFSupportsReading(format)) + dib = FreeImage_Load(format, filename); + //if the image failed to load, return failure + if (!dib) { + printf("Image failed to load, exiting.."); + exit(1); + } + + + bits = FreeImage_GetBits(dib); + width = FreeImage_GetWidth(dib); + height = FreeImage_GetHeight(dib); + typef = FreeImage_GetImageType(dib); + colorf = FreeImage_GetColorType(dib); + pixSz = FreeImage_GetBPP(dib); + + switch (colorf) { + case FIC_MINISBLACK: + //right now this is a special case for different types of FONT textures... + //converting single channel to rgba so shaders are the same... + //prob should be in its own font loader class, not a general texture loading method + printf("FIC_MINISBLACK\n"); + pixFormat = GL_RED; + //dib = FreeImage_ConvertTo32Bits(dib); + //pixFormat = GL_RGBA; + break; + case FIC_MINISWHITE: + printf("FIC_MINISWHITE\n"); + break; + case FIC_PALETTE: + printf("FIC_PALETTE\n"); + break; + case FIC_CMYK: + printf("FIC_CMYK\n"); + break; + case FIC_RGB: + printf("FIC_RGB\n"); + pixFormat = GL_BGR; + //dib = FreeImage_ConvertTo32Bits(dib); + //pixFormat = GL_RGB; + break; + case FIC_RGBALPHA: + printf("FIC_RGBA\n"); + pixFormat = GL_RGBA; + break; + default: + printf("format %d not handled!\n", colorf); + break; + } + + //probably want to have a single channel format plus a single+alpha + + printf("format = %d\n", format); + printf("Image type = %d\n", typef); + printf("w/h = %d/%d\n", width, height); + printf("pixel bit size: %d\n", pixSz); + printf("FreeImage_IsTransparent = %d\n", FreeImage_IsTransparent(dib)); + printf("FreeImage_FlipHorizontal = %d\n", FreeImage_FlipHorizontal(dib)); + + memcpy((GLubyte*)data, (GLubyte*)bits, width * height * 3); + FreeImage_Unload(dib); + } + + + void ResourceHandler::loadTexture(Texture &t, const std::string &name) { + + FreeImage_Initialise(); // Need this call to ensure FreeImage works... + + const char *filename = name.c_str(); + FREE_IMAGE_FORMAT format = FIF_UNKNOWN; + FIBITMAP *dib(0); + BYTE *bits(0); + unsigned int width(0), height(0), pixSz(0); + FREE_IMAGE_COLOR_TYPE colorf; + FREE_IMAGE_TYPE typef; + GLenum pixFormat = GL_RGBA; + + //check the file signature and deduce its format + format = FreeImage_GetFileType(filename, 0); + //if still unknown, try to guess the file format from the file extension + if (format == FIF_UNKNOWN) + format = FreeImage_GetFIFFromFilename(filename); + //if still unkown, return failure + if (format == FIF_UNKNOWN) { + printf("Unable to load file, exiting.."); + exit(1); + } + + //check that the plugin has reading capabilities and load the file + if (FreeImage_FIFSupportsReading(format)) + dib = FreeImage_Load(format, filename); + //if the image failed to load, return failure + if (!dib) { + printf("Image failed to load, exiting.."); + exit(1); + } + + + bits = FreeImage_GetBits(dib); + width = FreeImage_GetWidth(dib); + height = FreeImage_GetHeight(dib); + typef = FreeImage_GetImageType(dib); + colorf = FreeImage_GetColorType(dib); + pixSz = FreeImage_GetBPP(dib); + + switch (colorf) { + case FIC_MINISBLACK: + //right now this is a special case for different types of FONT textures... + //converting single channel to rgba so shaders are the same... + //prob should be in its own font loader class, not a general texture loading method + printf("FIC_MINISBLACK\n"); + pixFormat = GL_RED; + //dib = FreeImage_ConvertTo32Bits(dib); + //pixFormat = GL_RGBA; + break; + case FIC_MINISWHITE: + printf("FIC_MINISWHITE\n"); + break; + case FIC_PALETTE: + printf("FIC_PALETTE\n"); + break; + case FIC_CMYK: + printf("FIC_CMYK\n"); + break; + case FIC_RGB: + printf("FIC_RGB\n"); + pixFormat = GL_BGR; + //dib = FreeImage_ConvertTo32Bits(dib); + //pixFormat = GL_RGB; + break; + case FIC_RGBALPHA: + printf("FIC_RGBA\n"); + pixFormat = GL_RGBA; + break; + default: + printf("format %d not handled!\n", colorf); + break; + } + + //probably want to have a single channel format plus a single+alpha + + printf("format = %d\n", format); + printf("Image type = %d\n", typef); + printf("w/h = %d/%d\n", width, height); + printf("pixel bit size: %d\n", pixSz); + printf("FreeImage_IsTransparent = %d\n", FreeImage_IsTransparent(dib)); + printf("FreeImage_FlipHorizontal = %d\n", FreeImage_FlipHorizontal(dib)); + + GLubyte* data = (GLubyte*)malloc((width * height * 3)); + memcpy((GLubyte*)data, (GLubyte*)bits, width * height * 3); + + t = Texture(data, width, height, GL_RGBA, pixFormat, GL_UNSIGNED_BYTE); + FreeImage_Unload(dib); + + } + + void ResourceHandler::loadCubeMapTexture(Texture &t, int w, int h, + const std::string &negz, + const std::string &posz, + const std::string &posy, + const std::string &negy, + const std::string &negx, + const std::string &posx) { + + GLubyte* d1 = new GLubyte[w * h * 4]; + loadImageData(d1, negz); + + GLubyte* d2 = new GLubyte[w * h * 4]; + loadImageData(d2, posz); + + GLubyte* d3 = new GLubyte[w * h * 4]; + loadImageData(d3, posy); + + GLubyte* d4 = new GLubyte[w * h * 4]; + loadImageData(d4, negy); + + GLubyte* d5 = new GLubyte[w * h * 4]; + loadImageData(d5, negx); + + GLubyte* d6 = new GLubyte[w * h * 4]; + loadImageData(d6, posx); + + t = aluminum::Texture(d1, d2, d3, d4, d5, d6, w, h, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); + + + } + }