Graphics module refactored.

This commit is contained in:
Martín Lucas Golini
2014-06-22 20:29:23 -03:00
parent 2d3fb40c16
commit 0c7385a3c8
237 changed files with 2849 additions and 2848 deletions

View File

@@ -8,7 +8,7 @@ void MainLoop()
win->Clear();
// Create an instance of the primitive renderer
cPrimitives p;
Primitives p;
// Change the color
p.SetColor( ColorA( 0, 255, 0, 150 ) );

View File

@@ -12,7 +12,7 @@ Uint32 ParticlesNum = 30000;
EE::Window::Window * win = NULL;
Input * imp = NULL;
cShaderProgram * ShaderProgram = NULL;
ShaderProgram * shaderProgram = NULL;
bool ShadersSupported = false;
Float tw;
Float th;
@@ -66,24 +66,24 @@ void videoResize( EE::Window::Window * w ) {
BlendMode::SetMode( ALPHA_BLENDONE );
/// Set the line width
cGlobalBatchRenderer::instance()->SetLineWidth( 2 );
GlobalBatchRenderer::instance()->SetLineWidth( 2 );
if ( ShadersSupported ) {
/// Rebind the Shader
ShaderProgram->Bind();
shaderProgram->Bind();
/// If you want to use the programmable-pipeline renderer you'll need to set up the projection and modelview matrix manually.
/// Or if you want to use another name to the projection matrix or the modelview matrix ( eepp programmable-pipeline use
/// dgl_ProjectionMatrix and dgl_ModelViewMatrix by default.
if ( GLv_2 == GLi->Version() ) {
ShaderProgram->SetUniformMatrix( "dgl_ProjectionMatrix", perspectiveMatrix );
shaderProgram->SetUniformMatrix( "dgl_ProjectionMatrix", perspectiveMatrix );
/// Get the identity matrix and set it to the modelview matrix
float modelMatrix[16];
GLi->LoadIdentity();
GLi->GetCurrentMatrix( GL_MODELVIEW_MATRIX, modelMatrix );
ShaderProgram->SetUniformMatrix( "dgl_ModelViewMatrix", modelMatrix );
shaderProgram->SetUniformMatrix( "dgl_ModelViewMatrix", modelMatrix );
}
}
}
@@ -217,7 +217,7 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
/// We really don't need shaders for this, but the purpose of the example is to show how to work with external shaders
if ( ShadersSupported ) {
/// Disable the automatic shader conversion from fixed-pipeline to programmable-pipeline
cShader::Ensure( false );
Shader::Ensure( false );
std::string fs( "#ifdef GL_ES\n\
precision highp float;\n\
@@ -245,7 +245,7 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
}
/// Create the new shader program
ShaderProgram = cShaderProgram::New( vs.c_str(), vs.size(), fs.c_str(), fs.size() );
shaderProgram = ShaderProgram::New( vs.c_str(), vs.size(), fs.c_str(), fs.size() );
}
/// Set the projection

View File

@@ -1,12 +1,12 @@
#include <eepp/ee.hpp>
EE::Window::Window * win = NULL;
cTTFFont * TTF = NULL;
cTTFFont * TTFO = NULL;
cTTFFont * TTF2 = NULL;
cTextureFont * TexF = NULL;
cTextureFont * TexF2 = NULL;
cTextCache * TxtCache = NULL;
TTFFont * TTF = NULL;
TTFFont * TTFO = NULL;
TTFFont * TTF2 = NULL;
TextureFont * TexF = NULL;
TextureFont * TexF2 = NULL;
TextCache * TxtCache = NULL;
void MainLoop()
{
@@ -59,33 +59,33 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
std::string AppPath = Sys::GetProcessPath();
// Create a new True Type Font
TTF = cTTFFont::New( "DejaVuSansMonoOutline" );
TTFO = cTTFFont::New( "DejaVuSansMonoOutlineFreetype" );
TTF2 = cTTFFont::New( "DejaVuSansMono" );
TexF = cTextureFont::New( "ProggySquareSZ" );
TexF2 = cTextureFont::New( "conchars" );
TTF = TTFFont::New( "DejaVuSansMonoOutline" );
TTFO = TTFFont::New( "DejaVuSansMonoOutlineFreetype" );
TTF2 = TTFFont::New( "DejaVuSansMono" );
TexF = TextureFont::New( "ProggySquareSZ" );
TexF2 = TextureFont::New( "conchars" );
// Load the TTF font
TTF->Load( AppPath + "assets/fonts/DejaVuSansMono.ttf", 18, TTF_STYLE_NORMAL, 128, RGB(255,255,255), 3, RGB(0,0,0), true );
// Change the default method to use for outlining the font glyphs
cTTFFont::OutlineMethod = cTTFFont::OutlineFreetype;
TTFFont::OutlineMethod = TTFFont::OutlineFreetype;
// Create the exact same font than before but using the new outlining method
TTFO->Load( AppPath + "assets/fonts/DejaVuSansMono.ttf", 18, TTF_STYLE_NORMAL, 128, RGB(255,255,255), 3, RGB(0,0,0), true );
TTF2->Load( AppPath + "assets/fonts/DejaVuSansMono.ttf", 24, TTF_STYLE_NORMAL, 128, RGB(255,255,255), 0, RGB(0,0,0), true );
// Save the TTF font so then it can be loaded as a cTextureFont
// Save the TTF font so then it can be loaded as a TextureFont
TTF->Save( AppPath + "assets/temp/DejaVuSansMono.png", AppPath + "assets/temp/DejaVuSansMono.fnt" );
// Load the texture font, previusly generated from a True Type Font
// First load the texture
Uint32 TexFid = cTextureFactory::instance()->Load( AppPath + "assets/fonts/ProggySquareSZ.png" );
Uint32 TexFid = TextureFactory::instance()->Load( AppPath + "assets/fonts/ProggySquareSZ.png" );
TexF->Load( TexFid, AppPath + "assets/fonts/ProggySquareSZ.dat" );
// Load a monospaced texture font from image ( using the texture loader to set the color key )
cTextureLoader TexLoader( AppPath + "assets/fonts/conchars.png" );
TextureLoader TexLoader( AppPath + "assets/fonts/conchars.png" );
TexLoader.SetColorKey( RGB(0,0,0) );
TexLoader.Load();;
TexF2->Load( TexLoader.Id(), 32 );
@@ -109,7 +109,7 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
// Create a new text cache to draw on screen
// The cached text will
TxtCache = eeNew( cTextCache, ( TTF2, Txt, ColorA(0,0,0,255) ) );
TxtCache = eeNew( TextCache, ( TTF2, Txt, ColorA(0,0,0,255) ) );
// Set the text cache to be centered
TxtCache->Flags( FONT_DRAW_CENTER );

View File

@@ -8,18 +8,18 @@ Interpolation RockAngle;
Interpolation PlanetAngle;
// Create a primitive drawer instance to draw the AABB of the Rock
cPrimitives P;
cSprite * Rock = NULL;
cSprite * Planet = NULL;
cSprite * Blindy = NULL;
Primitives P;
Sprite * Rock = NULL;
Sprite * Planet = NULL;
Sprite * Blindy = NULL;
// Define a user sprite event
static const Uint32 USER_SPRITE_EVENT = cSprite::SPRITE_EVENT_USER + 1;
static const Uint32 USER_SPRITE_EVENT = Sprite::SPRITE_EVENT_USER + 1;
// Get the sprite event callback
void spriteCallback( Uint32 Event, cSprite * Sprite, void * UserData ) {
void spriteCallback( Uint32 Event, Sprite * Sprite, void * UserData ) {
// Sprite Animation entered the first frame?
if ( Event == cSprite::SPRITE_EVENT_FIRST_FRAME ) {
if ( Event == Sprite::SPRITE_EVENT_FIRST_FRAME ) {
// Fire a user Event
Sprite->FireEvent( USER_SPRITE_EVENT );
} else if ( Event == USER_SPRITE_EVENT ) {
@@ -99,14 +99,14 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
std::string AppPath = Sys::GetProcessPath();
// Load the rock texture
Uint32 PlanetId = cTextureFactory::instance()->Load( AppPath + "assets/sprites/7.png" );
Uint32 RockId = cTextureFactory::instance()->Load( AppPath + "assets/sprites/5.png" );
Uint32 PlanetId = TextureFactory::instance()->Load( AppPath + "assets/sprites/7.png" );
Uint32 RockId = TextureFactory::instance()->Load( AppPath + "assets/sprites/5.png" );
// Load a previously generated texture atlas that contains the SubTextures needed to load an animated sprite
cTextureAtlasLoader Blindies( AppPath + "assets/atlases/bnb.eta" );
TextureAtlasLoader Blindies( AppPath + "assets/atlases/bnb.eta" );
// Create the animated rock spriteR
Rock = eeNew( cSprite, () );
Rock = eeNew( Sprite, () );
// Load the rock frames from the texture, adding the frames manually
for ( Int32 my = 0; my < 4; my++ ) {
@@ -117,14 +117,14 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
}
// Create a static sprite
Planet = eeNew( cSprite, ( PlanetId ) );
Planet = eeNew( Sprite, ( PlanetId ) );
// This constructor is the same that creating sprite and calling Sprite.AddFramesByPattern.
// It will look for a SubTexture ( in any Texture Atlas loaded, or the GlobalTextureAtlas ) animation by its name, it will search
// for "gn00" to "gnXX" to create a new animation
// see cTextureAtlasManager::GetSubTexturesByPattern for more information.
// see TextureAtlasManager::GetSubTexturesByPattern for more information.
// This is the easiest way to load animated sprites.
Blindy = eeNew( cSprite, ( "gn" ) );
Blindy = eeNew( Sprite, ( "gn" ) );
// Set the sprite animation speed, set in Frames per Second
// Sprites are auto-animated by default.

View File

@@ -1,15 +1,15 @@
#include <eepp/ee.hpp>
EE::Window::Window * win = NULL;
cVertexBuffer * VBO = NULL;
cVertexBuffer * VBO2 = NULL;
cFrameBuffer * FBO = NULL;
VertexBuffer * VBO = NULL;
VertexBuffer * VBO2 = NULL;
FrameBuffer * FBO = NULL;
// The batch renderer class is designed to take control of almost all the rendering needed by the engine.
// Controls that the rendering is only done when is needed, preventing redundant OpenGL API calls
// Usually the user will not need to use this class manually, since eepp controls this internally.
// The engine uses the singleton class cGlobalBatchRenderer instance to render textures and primitives.
cBatchRenderer * Batch = eeNew( cBatchRenderer, () );
// The engine uses the singleton class GlobalBatchRenderer instance to render textures and primitives.
BatchRenderer * Batch = eeNew( BatchRenderer, () );
Float ang = 0, scale = 1;
bool side = false;
@@ -124,8 +124,8 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
// Create the Vertex Buffer, the vertex buffer stores the vertex data in the GPU, making the rendering much faster
// In the case that Vertex Buffer Object is not supported by the GPU, it will fallback to a inmediate-mode vertex buffer
VBO = cVertexBuffer::New( VERTEX_FLAGS_PRIMITIVE, DM_TRIANGLE_FAN );
VBO2 = cVertexBuffer::New( VERTEX_FLAGS_PRIMITIVE, DM_TRIANGLE_FAN );
VBO = VertexBuffer::New( VERTEX_FLAGS_PRIMITIVE, DM_TRIANGLE_FAN );
VBO2 = VertexBuffer::New( VERTEX_FLAGS_PRIMITIVE, DM_TRIANGLE_FAN );
// Add the vertex and vertex colors to the Vertex Buffer
if ( NULL != VBO && NULL != VBO2 ) {
@@ -147,7 +147,7 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
}
// Create a new frame buffer. It will use Framebuffer Objects if available, otherwise it will try to fallback to PBuffers.
FBO = cFrameBuffer::New( 200, 200 );
FBO = FrameBuffer::New( 200, 200 );
// Application loop
win->RunMainLoop( &MainLoop );