diff --git a/include/audio/Source.hpp b/include/audio/Source.hpp index 0c720b6..9882683 100644 --- a/include/audio/Source.hpp +++ b/include/audio/Source.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Source.hpp,v 1.1 2005/07/05 06:44:56 cozman Exp $ +// $Id: Source.hpp,v 1.2 2005/07/17 07:14:09 cozman Exp $ #ifndef PHOTON_AUDIO_SOURCE_HPP #define PHOTON_AUDIO_SOURCE_HPP @@ -251,7 +251,7 @@ void Source::rewind() template void Source::setLooping(bool loop) { - alSourcefv(sourceID_, AL_LOOPING, loop); + alSourcei(sourceID_, AL_LOOPING, loop); } template diff --git a/include/video/Font.hpp b/include/video/Font.hpp index 34f88a6..5d0962a 100644 --- a/include/video/Font.hpp +++ b/include/video/Font.hpp @@ -5,13 +5,14 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Font.hpp,v 1.4 2005/07/04 03:06:48 cozman Exp $ +// $Id: Font.hpp,v 1.5 2005/07/17 07:14:09 cozman Exp $ #ifndef PHOTON_VIDEO_FONT_HPP #define PHOTON_VIDEO_FONT_HPP #include "video/FontResourceManager.hpp" #include "ResourceManaged.hpp" +#include "video/Color.hpp" namespace photon { @@ -74,6 +75,22 @@ public: Font& operator=(const Font &rhs); operator bool() const; +// Group: Coloring +public: + // Function: setColor + // Set draw color of the font. + // + // Parameters: + // color - to shade font glyphs when drawn. + void setColor(const Color& color); + + // Function: getColor + // Get draw color of the font. + // + // Returns: + // Currently set to shade font glyphs when drawn. + Color getColor() const; + // Group: Drawing public: void drawText(float x, float y, const char *str, ...) const; @@ -120,6 +137,8 @@ private: std::ostringstream ss_; float drawX_; float drawY_; + // color + Color color_; }; } diff --git a/photon.mm b/photon.mm index 774f05d..6e7da2c 100644 --- a/photon.mm +++ b/photon.mm @@ -8,11 +8,17 @@ - + + + + + + + @@ -33,8 +39,7 @@ - - + @@ -76,7 +81,7 @@ - + diff --git a/src/video/Font.cpp b/src/video/Font.cpp index 089f801..d4fd374 100644 --- a/src/video/Font.cpp +++ b/src/video/Font.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Font.cpp,v 1.4 2005/07/04 03:06:48 cozman Exp $ +// $Id: Font.cpp,v 1.5 2005/07/17 07:14:09 cozman Exp $ #include "video/Font.hpp" @@ -71,6 +71,16 @@ Font::operator bool() const return isValid(); } +void Font::setColor(const Color& color) +{ + color_ = color; +} + +Color Font::getColor() const +{ + return color_; +} + void Font::drawText(float x, float y, const char *str, ...) const { if(!isValid()) @@ -85,6 +95,10 @@ void Font::drawText(float x, float y, const char *str, ...) const std::vsnprintf(buf, 1024, str, args); // avoid buffer overflow va_end(args); + // push attrib before setting color + glPushAttrib(GL_CURRENT_BIT); + glColor4ub(color_.red, color_.green, color_.blue, color_.alpha); + glBindTexture(GL_TEXTURE_2D, texID_); glPushMatrix(); glTranslated(x,y,0); @@ -106,6 +120,7 @@ void Font::drawText(float x, float y, const char *str, ...) const //glCallLists(static_cast(std::strlen(buf)), GL_UNSIGNED_BYTE, buf); glPopMatrix(); + glPopAttrib(); } void Font::drawText(float x, float y, const std::string& str) const @@ -115,6 +130,10 @@ void Font::drawText(float x, float y, const std::string& str) const throw PreconditionException("Invalid Font::drawText call."); } + // push attrib before setting color + glPushAttrib(GL_CURRENT_BIT); + glColor4ub(color_.red, color_.green, color_.blue, color_.alpha); + glBindTexture(GL_TEXTURE_2D, texID_); glPushMatrix(); glTranslated(x,y,0); @@ -136,6 +155,7 @@ void Font::drawText(float x, float y, const std::string& str) const //glCallLists(static_cast(std::strlen(buf)), GL_UNSIGNED_BYTE, buf); glPopMatrix(); + glPopAttrib(); } std::ostream& Font::beginDraw(float x, float y) diff --git a/test/Audio_test.cpp b/test/Audio_test.cpp index 3991660..bcf70e3 100644 --- a/test/Audio_test.cpp +++ b/test/Audio_test.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Audio_test.cpp,v 1.1 2005/07/06 02:10:07 cozman Exp $ +// $Id: Audio_test.cpp,v 1.2 2005/07/17 07:14:09 cozman Exp $ #include "photon.hpp" using namespace photon; @@ -28,29 +28,160 @@ public: log.addSink(csp); video.setOrthoView(800,600); + + video::Font::addResource("font","data/FreeMono.ttf",20); + font.open("font"); - Sample::addResource("wavdata/ocean.wav"); - sample.open("wavdata/ocean.wav"); - sample.play(); + Sample::addResource("chimes","data/chimes.wav"); + Sample::addResource("ocean","data/ocean.wav"); + Sample::addResource("rain","data/rain.wav"); + Sample::addResource("stream","data/stream.wav"); + Sample::addResource("thunder","data/thunder.wav"); + Sample::addResource("waterdrop","data/waterdrop.wav"); + + chimes.open("chimes"); + ocean.open("ocean"); + rain.open("rain"); + stream.open("stream"); + thunder.open("thunder"); + waterdrop.open("waterdrop"); + + chimes.setLooping(true); + ocean.setLooping(true); + rain.setLooping(true); + stream.setLooping(true); + thunder.setLooping(true); + waterdrop.setLooping(true); + + for(int i=0; i < 6; ++i) + status[i] = "NOT "; + } + + void checkKeys() + { + static const std::string NOT_PLAYING = "NOT "; + static scalar lastCheck = 0; + + if(app.getTime() - lastCheck > 0.1) + { + lastCheck = app.getTime(); + + if(app.keyPressed(KEY_C)) + { + if(status[0] == NOT_PLAYING) + { + chimes.play(); + status[0] = ""; + } + else + { + chimes.stop(); + status[0] = NOT_PLAYING; + } + } + if(app.keyPressed(KEY_O)) + { + if(status[1] == NOT_PLAYING) + { + ocean.play(); + status[1] = ""; + } + else + { + ocean.stop(); + status[1] = NOT_PLAYING; + } + } + if(app.keyPressed(KEY_R)) + { + if(status[2] == NOT_PLAYING) + { + rain.play(); + status[2] = ""; + } + else + { + rain.stop(); + status[2] = NOT_PLAYING; + } + } + if(app.keyPressed(KEY_S)) + { + if(status[3] == NOT_PLAYING) + { + stream.play(); + status[3] = ""; + } + else + { + stream.stop(); + status[3] = NOT_PLAYING; + } + } + if(app.keyPressed(KEY_T)) + { + if(status[4] == NOT_PLAYING) + { + thunder.play(); + status[4] = ""; + } + else + { + thunder.stop(); + status[4] = NOT_PLAYING; + } + } + if(app.keyPressed(KEY_W)) + { + if(status[5] == NOT_PLAYING) + { + waterdrop.play(); + status[5] = ""; + } + else + { + waterdrop.stop(); + status[5] = NOT_PLAYING; + } + } + } } void update() - { + { + static const photon::uint fontHeight(font.getHeight()); static double t=0; - + if(app.getTime() - t > 1.0) { app.setTitle("FPS: " + boost::lexical_cast(app.getFramerate()) ); t = app.getTime(); } - + + checkKeys(); + video.clear(); + font.beginDraw(0, 0*fontHeight) << "(C)himes is " << status[0] << + "playing" << font.endDraw(); + font.beginDraw(0, 1*fontHeight) << "(O)cean is " << status[1] << + "playing" << font.endDraw(); + font.beginDraw(0, 2*fontHeight) << "(R)ain is " << status[2] << + "playing" << font.endDraw(); + font.beginDraw(0, 3*fontHeight) << "(S)tream is " << status[3] << + "playing" << font.endDraw(); + font.beginDraw(0, 4*fontHeight) << "(T)hunder is " << status[4] << + "playing" << font.endDraw(); + font.beginDraw(0, 5*fontHeight) << "(W)aterdrop is " << status[5] << + "playing" << font.endDraw(); + } private: - audio::Sample sample; + video::Font font; + audio::Sample chimes, ocean, rain, stream, thunder, waterdrop; + std::string status[6]; Log log; AppCore& app; diff --git a/test/Font_test.cpp b/test/Font_test.cpp index a32c1cc..a476401 100644 --- a/test/Font_test.cpp +++ b/test/Font_test.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Font_test.cpp,v 1.4 2005/07/04 03:06:48 cozman Exp $ +// $Id: Font_test.cpp,v 1.5 2005/07/17 07:14:09 cozman Exp $ #include "photon.hpp" using namespace photon; @@ -30,11 +30,12 @@ public: video.setOrthoView(800,600); - video::Font::addResource("font1","data/arial.ttf",32); - video::Font::addResource("font2","data/FreeMono.ttf",18); + video::Font::addResource("font1","data/FreeMono.ttf",32); + video::Font::addResource("font2","data/FreeSerif.ttf",18); font.open("font1"); font2.open("font2"); + } void update() @@ -50,10 +51,12 @@ public: video.clear(); + font.setColor(video::Color(0,128,128)); font.drawText(0, 0, "Photon"); + font.setColor(video::Color(255,0,0)); font.drawText(font.calcStringWidth("Photon"), font.getHeight(), "FPS: %.0f", app.getFramerate() ); - font2.beginDraw(200, 200) << "another font" << font2.endDraw(); + font2.beginDraw(200, 200) << "another plain font" << font2.endDraw(); } private: