Made all the examples Emscripten friendly.

cWindow::Display( bool clear = false ) now doesn't Clear by default.
Fixed a bug in cSprite::GetAABB().
This commit is contained in:
Martín Lucas Golini
2013-11-14 02:30:46 -03:00
parent d40a10a07c
commit 2e016791da
10 changed files with 314 additions and 270 deletions

View File

@@ -227,15 +227,15 @@ class EE_API cWindow {
/** @return The window handler */
virtual eeWindowHandle GetWindowHandler() = 0;
/** Clear the current window
/** @brief Clear the window back buffer
This function is usually called once every frame, to clear the previous frame content.
*/
virtual void Clear();
/** Render the Scene to Screen
@param clear Clear after swapping buffers?
@param clear Clear after swapping buffers? It will not work if the target platform is Emscripten. Since there's no swap buffers.
*/
virtual void Display( bool clear = true );
virtual void Display( bool clear = false );
/** @return The elapsed time for the last frame rendered */
virtual cTime Elapsed() const;

View File

@@ -297,6 +297,15 @@ function build_link_configuration( package_name, use_ee_icon )
if os.is_real("emscripten") then
extension = ".html"
if ( package_name ~= "eeew" and
package_name ~= "eees" and
package_name ~= "eehttp-request" and
package_name ~= "eephysics" and
package_name ~= "eevbo-fbo-batch"
) then
linkoptions { "--preload-file assets/" }
end
end
end
@@ -331,17 +340,6 @@ function build_link_configuration( package_name, use_ee_icon )
if _OPTIONS["with-gles2"] and not _OPTIONS["force-gles1"] then
linkoptions{ "-s FULL_ES2=1" }
end
if ( package_name ~= "eepp" and
package_name ~= "eepp-static" and
package_name ~= "eepp-ew" and
package_name ~= "eepp-es" and
package_name ~= "eepp-http-request" and
package_name ~= "eepp-physics" and
package_name ~= "eepp-vbo-fbo-batch"
) then
linkoptions { "--preload-file assets/" }
end
set_ios_config()
end

View File

@@ -296,7 +296,7 @@ eeAABB cSprite::GetAABB() {
Center += mPos;
}
TmpR.Scale( mScale, mOrigin );
TmpR.Scale( mScale, Center );
}
}

View File

@@ -4,6 +4,7 @@ cWindow * win = NULL;
void MainLoop()
{
// Clear the screen buffer
win->Clear();
// Create an instance of the primitive renderer
@@ -22,12 +23,13 @@ void MainLoop()
}
// Draw a circle
p.DrawCircle( eeVector2f( win->GetWidth() * 0.5f, win->GetHeight() * 0.5f ), 200 );
p.DrawCircle( eeVector2f( win->GetWidth() * 0.5f, win->GetHeight() * 0.5f ), 200, 50 );
// Draw frame
win->Display(false);
win->Display();
}
// EE_MAIN_FUNC is needed by some platforms to be able to find the real application main
EE_MAIN_FUNC int main (int argc, char * argv [])
{
// Create a new window with vsync enabled
@@ -38,7 +40,15 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
// Set window background color
win->BackColor( eeColor( 50, 50, 50 ) );
win->RunMainLoop( &MainLoop, 60 );
// Set the MainLoop function and run it
// This is the application loop, it will loop until the window is closed.
// This is only a requirement if you want to support Emscripten builds ( WebGL + Canvas ).
// This is the same as, except for Emscripten.
// while ( win->Running() )
// {
// MainLoop();
// }
win->RunMainLoop( &MainLoop );
}
// Destroy the engine instance. Destroys all the windows and engine singletons.

View File

@@ -199,7 +199,7 @@ void MainLoop()
Sys::Sleep( 100 ); /// Sleep 100 ms
}
win->Display( false );
win->Display();
}
EE_MAIN_FUNC int main (int argc, char * argv [])

View File

@@ -1,9 +1,54 @@
#include <eepp/ee.hpp>
cWindow * win = NULL;
cTTFFont * TTF = NULL;
cTTFFont * TTFO = NULL;
cTTFFont * TTF2 = NULL;
cTextureFont * TexF = NULL;
cTextureFont * TexF2 = NULL;
cTextCache * TxtCache = NULL;
void MainLoop()
{
// Clear the screen buffer
win->Clear();
// Update the input
win->GetInput()->Update();
// Check if ESCAPE key is pressed
if ( win->GetInput()->IsKeyDown( KEY_ESCAPE ) ) {
// Close the window
win->Close();
}
eeFloat YPos = 32;
// Draw the text on screen
TTF->Draw( win->GetWidth() * 0.5f - TTF->GetTextWidth() * 0.5f, YPos );
TTFO->Draw( win->GetWidth() * 0.5f - TTFO->GetTextWidth() * 0.5f, ( YPos += TTF->GetTextHeight() + 24 ) );
TTF2->Draw( win->GetWidth() * 0.5f - TTF2->GetTextWidth() * 0.5f, ( YPos += TTF->GetTextHeight() + 24 ) );
TexF->Draw( win->GetWidth() * 0.5f - TexF->GetTextWidth() * 0.5f, ( YPos += TTF2->GetTextHeight() + 24 ) );
TexF2->Draw( win->GetWidth() * 0.5f - TexF2->GetTextWidth() * 0.5f, ( YPos += TexF->GetTextHeight() + 24 ) );
// Draw the cached text
TxtCache->Draw( 48, ( YPos += TexF2->GetTextHeight() + 24 ) );
// Text rotated and scaled
TTF->Draw( win->GetWidth() * 0.5f - TTF->GetTextWidth() * 0.5f, 512, FONT_DRAW_LEFT, 0.75f, 12.5f );
// Draw frame
win->Display();
}
EE_MAIN_FUNC int main (int argc, char * argv [])
{
// Create a new window
cWindow * win = cEngine::instance()->CreateWindow( WindowSettings( 960, 640, "eepp - Fonts" ), ContextSettings( true ) );
win = cEngine::instance()->CreateWindow( WindowSettings( 960, 640, "eepp - Fonts" ), ContextSettings( true ) );
// Set window background color
win->BackColor( eeColor(255,255,255) );
@@ -14,11 +59,11 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
std::string AppPath = Sys::GetProcessPath();
// Create a new True Type Font
cTTFFont * TTF = cTTFFont::New( "DejaVuSansMonoOutline" );
cTTFFont * TTFO = cTTFFont::New( "DejaVuSansMonoOutlineFreetype" );
cTTFFont * TTF2 = cTTFFont::New( "DejaVuSansMono" );
cTextureFont * TexF = cTextureFont::New( "ProggySquareSZ" );
cTextureFont * TexF2 = cTextureFont::New( "conchars" );
TTF = cTTFFont::New( "DejaVuSansMonoOutline" );
TTFO = cTTFFont::New( "DejaVuSansMonoOutlineFreetype" );
TTF2 = cTTFFont::New( "DejaVuSansMono" );
TexF = cTextureFont::New( "ProggySquareSZ" );
TexF2 = cTextureFont::New( "conchars" );
// Load the TTF font
TTF->Load( AppPath + "assets/fonts/DejaVuSansMono.ttf", 18, TTF_STYLE_NORMAL, 128, eeColor(255,255,255), 3, eeColor(0,0,0), true );
@@ -64,55 +109,26 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
// Create a new text cache to draw on screen
// The cached text will
cTextCache TxtCache( TTF2, Txt, eeColorA(0,0,0,255) );
TxtCache = eeNew( cTextCache, ( TTF2, Txt, eeColorA(0,0,0,255) ) );
// Set the text cache to be centered
TxtCache.Flags( FONT_DRAW_CENTER );
TxtCache->Flags( FONT_DRAW_CENTER );
// Set the font color to a substring of the text
// To be able to set the color of the font, create the font as white
// Create a gradient
size_t size = TxtCache.Text().size();
size_t size = TxtCache->Text().size();
for ( size_t i = 0; i < size; i++ ) {
TxtCache.Color( eeColorA(255*i/size,0,0,255), i, i+1 );
TxtCache->Color( eeColorA(255*i/size,0,0,255), i, i+1 );
}
// Application loop
while ( win->Running() ) {
// Update the input
win->GetInput()->Update();
// Check if ESCAPE key is pressed
if ( win->GetInput()->IsKeyDown( KEY_ESCAPE ) ) {
// Close the window
win->Close();
}
eeFloat YPos = 32;
// Draw the text on screen
TTF->Draw( win->GetWidth() * 0.5f - TTF->GetTextWidth() * 0.5f, YPos );
TTFO->Draw( win->GetWidth() * 0.5f - TTFO->GetTextWidth() * 0.5f, ( YPos += TTF->GetTextHeight() + 24 ) );
TTF2->Draw( win->GetWidth() * 0.5f - TTF2->GetTextWidth() * 0.5f, ( YPos += TTF->GetTextHeight() + 24 ) );
TexF->Draw( win->GetWidth() * 0.5f - TexF->GetTextWidth() * 0.5f, ( YPos += TTF2->GetTextHeight() + 24 ) );
TexF2->Draw( win->GetWidth() * 0.5f - TexF2->GetTextWidth() * 0.5f, ( YPos += TexF->GetTextHeight() + 24 ) );
// Draw the cached text
TxtCache.Draw( 48, ( YPos += TexF2->GetTextHeight() + 24 ) );
// Text rotated and scaled
TTF->Draw( win->GetWidth() * 0.5f - TTF->GetTextWidth() * 0.5f, 512, FONT_DRAW_LEFT, 0.75f, 12.5f );
// Draw frame
win->Display();
}
win->RunMainLoop( &MainLoop );
}
eeSAFE_DELETE( TxtCache );
// Destroy the engine instance. Destroys all the windows and engine singletons.
// Fonts are autoreleased by the engine
cEngine::DestroySingleton();

View File

@@ -5,9 +5,6 @@ The physics module is a OOP wrapper for Chipmunk Physics.
To understand the conceptos of space, body, shapes, etc you can read the
Chipmunk documentation:
http://chipmunk-physics.net/release/ChipmunkLatest-Docs/
*/
typedef cb::Callback0<void> SceneCb;
@@ -608,6 +605,27 @@ void PhysicsDestroy() {
mDemo[ mCurDemo ].destroy();
}
void MainLoop()
{
mWindow->Clear();
KM->Update();
if ( KM->IsKeyDown( KEY_ESCAPE ) ) {
mWindow->Close();
}
PhysicsUpdate();
if ( KM->IsKeyUp( KEY_LEFT ) || KM->IsKeyUp( KEY_A ) ) {
ChangeDemo( mCurDemo - 1 );
} else if ( KM->IsKeyUp( KEY_RIGHT ) || KM->IsKeyUp( KEY_D ) ) {
ChangeDemo( mCurDemo + 1 );
}
mWindow->Display();
}
EE_MAIN_FUNC int main (int argc, char * argv [])
{
mWindow = cEngine::instance()->CreateWindow( WindowSettings( 1024, 768, "eepp - Physics" ), ContextSettings( true ) );
@@ -619,23 +637,7 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
PhysicsCreate();
while ( mWindow->Running() ) {
KM->Update();
if ( KM->IsKeyDown( KEY_ESCAPE ) ) {
mWindow->Close();
}
PhysicsUpdate();
if ( KM->IsKeyUp( KEY_LEFT ) ) {
ChangeDemo( mCurDemo - 1 );
} else if ( KM->IsKeyUp( KEY_RIGHT ) ) {
ChangeDemo( mCurDemo + 1 );
}
mWindow->Display();
}
mWindow->RunMainLoop( &MainLoop );
PhysicsDestroy();
}

View File

@@ -1,5 +1,18 @@
#include <eepp/ee.hpp>
cWindow * win = NULL;
// Define a interpolation to control the Rock sprite angle
cInterpolation RockAngle;
cInterpolation PlanetAngle;
// Create a primitive drawer instance to draw the AABB of the Rock
cPrimitives P;
cSprite * Rock = NULL;
cSprite * Planet = NULL;
cSprite * Blindy = NULL;
// Define a user sprite event
static const Uint32 USER_SPRITE_EVENT = cSprite::SPRITE_EVENT_USER + 1;
@@ -26,10 +39,59 @@ void spriteCallback( Uint32 Event, cSprite * Sprite, void * UserData ) {
}
}
void MainLoop()
{
// Clear the screen buffer
win->Clear();
// Update the input
win->GetInput()->Update();
// Check if ESCAPE key is pressed
if ( win->GetInput()->IsKeyDown( KEY_ESCAPE ) ) {
// Close the window
win->Close();
}
// Check if the D key was pressed
if ( win->GetInput()->IsKeyUp( KEY_D ) ) {
// Reverse the Rock animation
Rock->ReverseAnim( !Rock->ReverseAnim() );
}
// Update the angle interpolation
PlanetAngle.Update( win->Elapsed() );
RockAngle.Update( win->Elapsed() );
// Set the Planet and Rock angle from the interpolation
Planet->Angle( PlanetAngle.GetPos() );
Rock->Angle( RockAngle.GetPos() );
// Draw the static planet sprite
Planet->Draw();
// Draw the animated Rock sprite
Rock->Draw();
// Draw the blindy animation
Blindy->Draw();
// Draw the Rock Axis-Aligned Bounding Box
P.SetColor( eeColorA( 255, 255, 255, 255 ) );
P.DrawRectangle( Rock->GetAABB() );
// Draw the Rock Quad
P.SetColor( eeColorA( 255, 0, 0, 255 ) );
P.DrawQuad( Rock->GetQuad() );
// Draw frame
win->Display();
}
EE_MAIN_FUNC int main (int argc, char * argv [])
{
// Create a new window
cWindow * win = cEngine::instance()->CreateWindow( WindowSettings( 640, 480, "eepp - Sprites" ), ContextSettings( true ) );
win = cEngine::instance()->CreateWindow( WindowSettings( 640, 480, "eepp - Sprites" ), ContextSettings( true ) );
// Check if created
if ( win->Created() ) {
@@ -43,53 +105,50 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
// Load a previously generated texture atlas that contains the SubTextures needed to load an animated sprite
cTextureAtlasLoader Blindies( AppPath + "assets/atlases/bnb.eta" );
// Create some new sprites
cSprite Rock;
// Create the animated rock spriteR
Rock = eeNew( cSprite, () );
// Load the rock frames from the texture, adding the frames manually
for ( Int32 my = 0; my < 4; my++ ) {
for( Int32 mx = 0; mx < 8; mx++ ) {
// DestSize as 0,0 will use the SubTexture size
Rock.AddFrame( RockId, eeSizef( 0, 0 ), eeVector2i( 0, 0 ), eeRecti( mx * 64, my * 64, mx * 64 + 64, my * 64 + 64 ) );
Rock->AddFrame( RockId, eeSizef( 0, 0 ), eeVector2i( 0, 0 ), eeRecti( mx * 64, my * 64, mx * 64 + 64, my * 64 + 64 ) );
}
}
// Set the sprite animation speed, set in Frames per Second
// Sprites are auto-animated by default.
Rock.AnimSpeed( 32 );
cSprite Planet( PlanetId ); // Create a static sprite
// Create a static sprite
Planet = eeNew( cSprite, ( 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.
// This is the easiest way to load animated sprites.
cSprite Blindy( "gn" );
Blindy = eeNew( cSprite, ( "gn" ) );
// Set the sprite animation speed, set in Frames per Second
// Sprites are auto-animated by default.
Rock->AnimSpeed( 32 );
// Set the render mode of the sprite
Blindy.RenderMode( RN_MIRROR );
Blindy->RenderMode( RN_MIRROR );
// Set the Blend Mode of the sprite
Blindy.BlendMode( ALPHA_BLENDONE );
Blindy->BlendMode( ALPHA_BLENDONE );
// Create a primitive drawer instance to draw the AABB of the Rock
cPrimitives P;
// Set the primitive fill mode
P.FillMode( DRAW_LINE );
// Set the sprites position to the screen center
eeVector2i ScreenCenter( cEngine::instance()->GetWidth() / 2, cEngine::instance()->GetHeight() / 2 );
Planet.Position( ScreenCenter.x - Planet.GetAABB().Size().Width() / 2, ScreenCenter.y - Planet.GetAABB().Size().Height() / 2 );
Planet->Position( ScreenCenter.x - Planet->GetAABB().Size().Width() / 2, ScreenCenter.y - Planet->GetAABB().Size().Height() / 2 );
Rock.Position( ScreenCenter.x - Rock.GetAABB().Size().Width() / 2, ScreenCenter.y - Rock.GetAABB().Size().Height() / 2 );
Rock->Position( ScreenCenter.x - Rock->GetAABB().Size().Width() / 2, ScreenCenter.y - Rock->GetAABB().Size().Height() / 2 );
Blindy.Position( ScreenCenter.x - Blindy.GetAABB().Size().Width() / 2, ScreenCenter.y - Blindy.GetAABB().Size().Height() / 2 );
Blindy->Position( ScreenCenter.x - Blindy->GetAABB().Size().Width() / 2, ScreenCenter.y - Blindy->GetAABB().Size().Height() / 2 );
// Define a interpolation to control the Rock sprite angle
cInterpolation RockAngle;
cInterpolation PlanetAngle;
// Set the planet angle interpolation
PlanetAngle.AddWaypoint( 0 );
PlanetAngle.AddWaypoint( 360 );
PlanetAngle.SetTotalTime( Seconds( 10 ) );
@@ -97,56 +156,16 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
PlanetAngle.Start();
// Create a Event callback for the rock sprite
Rock.SetEventsCallback( cb::Make3( &spriteCallback ), &RockAngle );
Rock->SetEventsCallback( cb::Make3( &spriteCallback ), &RockAngle );
// Application loop
while ( win->Running() )
{
// Update the input
win->GetInput()->Update();
// Check if ESCAPE key is pressed
if ( win->GetInput()->IsKeyDown( KEY_ESCAPE ) ) {
// Close the window
win->Close();
}
// Check if the D key was pressed
if ( win->GetInput()->IsKeyUp( KEY_D ) ) {
// Reverse the Rock animation
Rock.ReverseAnim( !Rock.ReverseAnim() );
}
// Update the angle interpolation
PlanetAngle.Update( win->Elapsed() );
RockAngle.Update( win->Elapsed() );
// Set the Planet and Rock angle from the interpolation
Planet.Angle( PlanetAngle.GetPos() );
Rock.Angle( RockAngle.GetPos() );
// Draw the static planet sprite
Planet.Draw();
// Draw the animated Rock sprite
Rock.Draw();
// Draw the blindy animation
Blindy.Draw();
// Draw the Rock Axis-Aligned Bounding Box
P.SetColor( eeColorA( 255, 255, 255, 255 ) );
P.DrawRectangle( Rock.GetAABB() );
// Draw the Rock Quad
P.SetColor( eeColorA( 255, 0, 0, 255 ) );
P.DrawQuad( Rock.GetQuad() );
// Draw frame
win->Display();
}
win->RunMainLoop( &MainLoop );
}
eeSAFE_DELETE( Rock );
eeSAFE_DELETE( Planet );
eeSAFE_DELETE( Blindy );
// Destroy the engine instance. Destroys all the windows and engine singletons.
cEngine::DestroySingleton();

View File

@@ -1,9 +1,119 @@
#include <eepp/ee.hpp>
cWindow * win = NULL;
cVertexBuffer * VBO = NULL;
cVertexBuffer * VBO2 = NULL;
cFrameBuffer * 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, () );
eeFloat ang = 0, scale = 1;
bool side = false;
void MainLoop()
{
// Clear the screen buffer
win->Clear();
// Update the input
win->GetInput()->Update();
// Check if ESCAPE key is pressed
if ( win->GetInput()->IsKeyDown( KEY_ESCAPE ) ) {
// Close the window
win->Close();
}
// Bind the Frame Buffer, everything rendered from here will be rendered in the frame buffer
FBO->Bind();
{
// Bind the buffered data ( activate the buffer )
VBO->Bind();
// Draw the buffered data
VBO->Draw();
// Unbind the buffered data
VBO->Unbind();
// Same as above
VBO2->Bind();
VBO2->Draw();
VBO2->Unbind();
}
// Unbind the frame buffer. Stops rendering to the frame buffer
FBO->Unbind();
// Draw the frame buffer many times
for ( int y = 0; y < 5; y++ ) {
for ( int x = 0; x < 5; x++ ) {
FBO->GetTexture()->Draw( x * 200, y * 200, -ang, 1.f, eeColorA(255,255,255,100) );
}
}
eeFloat HWidth = win->GetWidth() * 0.5f;
eeFloat HHeight = win->GetHeight() * 0.5f;
// The batch can be rotated, scale and moved
Batch->BatchRotation( ang );
Batch->BatchScale( scale );
Batch->BatchCenter( eeVector2f( HWidth, HHeight ) );
// Create a quad to render
eeFloat aX = HWidth - 256.f;
eeFloat aY = HHeight - 256.f;
eeQuad2f TmpQuad(
eeVector2f( aX , aY ),
eeVector2f( aX , aY + 32.f ),
eeVector2f( aX + 32.f, aY + 32.f ),
eeVector2f( aX + 32.f, aY )
);
TmpQuad.Rotate( ang, eeVector2f( aX + 16.f, aY + 16.f ) );
// Begin drawing quads
Batch->QuadsBegin();
// Add some quads to the batch renderer
for ( Uint32 z = 0; z < 16; z++ ) {
for ( Uint32 y = 0; y < 16; y++ ) {
eeFloat tmpx = (eeFloat)z * 32.f;
eeFloat tmpy = (eeFloat)y * 32.f;
// Add the quad to the batch
Batch->QuadsSetColor( eeColorA( z * 16, 255, 255, 150 ) );
Batch->BatchQuadFree( TmpQuad[0].x + tmpx, TmpQuad[0].y + tmpy, TmpQuad[1].x + tmpx, TmpQuad[1].y + tmpy, TmpQuad[2].x + tmpx, TmpQuad[2].y + tmpy, TmpQuad[3].x + tmpx, TmpQuad[3].y + tmpy );
}
}
// Draw the batched quads
Batch->Draw();
// Add the rotation angle
ang+=win->Elapsed().AsMilliseconds() * 0.1f;
ang = (ang>=360) ? 0 : ang;
// Change the scale value
if (scale>=1.5f) {
scale = 1.5f;
side = true;
} else if (scale<=0.5f) {
side = false;
scale = 0.5f;
}
scale = (!side) ? scale+win->Elapsed().AsMilliseconds() * 0.00025f : scale-win->Elapsed().AsMilliseconds() * 0.00025f;
// Draw frame
win->Display();
}
EE_MAIN_FUNC int main (int argc, char * argv [])
{
// Create a new window
cWindow * win = cEngine::instance()->CreateWindow( WindowSettings( 1024, 768, "eepp - VBO - FBO and Batch Rendering" ), ContextSettings( true ) );
win = cEngine::instance()->CreateWindow( WindowSettings( 1024, 768, "eepp - VBO - FBO and Batch Rendering" ), ContextSettings( true ) );
// Set window background color
win->BackColor( eeColor( 50, 50, 50 ) );
@@ -14,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
cVertexBuffer * VBO = cVertexBuffer::New( VERTEX_FLAGS_PRIMITIVE, DM_TRIANGLE_FAN );
cVertexBuffer * VBO2 = cVertexBuffer::New( VERTEX_FLAGS_PRIMITIVE, DM_TRIANGLE_FAN );
VBO = cVertexBuffer::New( VERTEX_FLAGS_PRIMITIVE, DM_TRIANGLE_FAN );
VBO2 = cVertexBuffer::New( VERTEX_FLAGS_PRIMITIVE, DM_TRIANGLE_FAN );
// Add the vertex and vertex colors to the Vertex Buffer
if ( NULL != VBO && NULL != VBO2 ) {
@@ -37,115 +147,16 @@ 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.
cFrameBuffer * FBO = cFrameBuffer::New( 200, 200 );
// 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 unneeded OpenGL API calls
// Usually the user will not need to use this class manually, since eepp controls this internally,
// but it's exposed to the programmer, to take control of this if needed.
// The engine uses the singleton class cGlobalBatchRenderer instance to render textures and primitives.
cBatchRenderer Batch;
eeFloat ang = 0, scale = 1;
bool side = false;
FBO = cFrameBuffer::New( 200, 200 );
// Application loop
while ( win->Running() ) {
// Update the input
win->GetInput()->Update();
// Check if ESCAPE key is pressed
if ( win->GetInput()->IsKeyDown( KEY_ESCAPE ) ) {
// Close the window
win->Close();
}
// Bind the Frame Buffer, everything rendered from here will be rendered in the frame buffer
FBO->Bind();
{
// Bind the buffered data ( activate the buffer )
VBO->Bind();
// Draw the buffered data
VBO->Draw();
// Unbind the buffered data
VBO->Unbind();
// Same as above
VBO2->Bind();
VBO2->Draw();
VBO2->Unbind();
}
// Unbind the frame buffer. Stops rendering to the frame buffer
FBO->Unbind();
// Draw the frame buffer many times
for ( int y = 0; y < 5; y++ ) {
for ( int x = 0; x < 5; x++ ) {
FBO->GetTexture()->Draw( x * 200, y * 200, -ang, 1.f, eeColorA(255,255,255,100) );
}
}
eeFloat HWidth = win->GetWidth() * 0.5f;
eeFloat HHeight = win->GetHeight() * 0.5f;
// The batch can be rotated, scale and moved
Batch.BatchRotation( ang );
Batch.BatchScale( scale );
Batch.BatchCenter( eeVector2f( HWidth, HHeight ) );
// Create a quad to render
eeFloat aX = HWidth - 256.f;
eeFloat aY = HHeight - 256.f;
eeQuad2f TmpQuad(
eeVector2f( aX , aY ),
eeVector2f( aX , aY + 32.f ),
eeVector2f( aX + 32.f, aY + 32.f ),
eeVector2f( aX + 32.f, aY )
);
TmpQuad.Rotate( ang, eeVector2f( aX + 16.f, aY + 16.f ) );
// Begin drawing quads
Batch.QuadsBegin();
// Add some quads to the batch renderer
for ( Uint32 z = 0; z < 16; z++ ) {
for ( Uint32 y = 0; y < 16; y++ ) {
eeFloat tmpx = (eeFloat)z * 32.f;
eeFloat tmpy = (eeFloat)y * 32.f;
// Add the quad to the batch
Batch.QuadsSetColor( eeColorA( z * 16, 255, 255, 150 ) );
Batch.BatchQuadFree( TmpQuad[0].x + tmpx, TmpQuad[0].y + tmpy, TmpQuad[1].x + tmpx, TmpQuad[1].y + tmpy, TmpQuad[2].x + tmpx, TmpQuad[2].y + tmpy, TmpQuad[3].x + tmpx, TmpQuad[3].y + tmpy );
}
}
// Draw the batched quads
Batch.Draw();
// Add the rotation angle
ang+=win->Elapsed().AsMilliseconds() * 0.1f;
ang = (ang>=360) ? 0 : ang;
// Change the scale value
if (scale>=1.5f) {
scale = 1.5f;
side = true;
} else if (scale<=0.5f) {
side = false;
scale = 0.5f;
}
scale = (!side) ? scale+win->Elapsed().AsMilliseconds() * 0.00025f : scale-win->Elapsed().AsMilliseconds() * 0.00025f;
// Draw frame
win->Display();
}
win->RunMainLoop( &MainLoop );
// Release the allocated objects ( VBOs and FBOs need to be released manually )
eeSAFE_DELETE( VBO );
eeSAFE_DELETE( VBO2 );
eeSAFE_DELETE( FBO );
eeSAFE_DELETE( Batch );
}
// Destroy the engine instance. Destroys all the windows and engine singletons.

View File

@@ -1,14 +1,10 @@
#include "eetest.hpp"
Demo_Test::cEETest * MY_INSTANCE = NULL;
Demo_Test::cEETest * TestInstance = NULL;
#if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN
#include <emscripten.h>
void MainLoop() {
MY_INSTANCE->Update();
static void MainLoop() {
TestInstance->Update();
}
#endif
namespace Demo_Test {
@@ -1612,17 +1608,9 @@ void cEETest::Process() {
Init();
if ( NULL != mWindow && mWindow->Created() ) {
#if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN
cLog::instance()->Write( "Entering the main loop" );
MY_INSTANCE = this;
TestInstance = this;
emscripten_set_main_loop(MainLoop, 0, 1);
#else
// Application loop
while ( mWindow->Running() ) {
Update();
}
#endif
mWindow->RunMainLoop( &MainLoop );
}
End();