Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spark demos patches #22

Open
wants to merge 5 commits into
base: spark2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions demos/src/SPKCollision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@
#if defined(WIN32) || defined(_WIN32)
#include <windows.h>
#endif

#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif

#include <SDL.h>
#include <SPARK.h>
Expand Down Expand Up @@ -228,22 +234,29 @@ int main(int argc, char *argv[])
{
// Inits SDL
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("SPARK Collision 2 Demo",NULL);

SDL_Window* window = SDL_CreateWindow("SPARK Collision 2 Demo",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
0, 0,
SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_OPENGL);

SDL_GL_CreateContext(window);

SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,0); // vsync
SDL_GL_SetSwapInterval(0);

SDL_SetVideoMode(0,0,32,SDL_OPENGL | SDL_FULLSCREEN);
SDL_ShowCursor(0);

SDL_Surface& screen = *SDL_GetVideoSurface();
SDL_SetRelativeMouseMode(SDL_TRUE);

// Inits openGL
int screenWidth = screen.w;
int screenHeight = screen.h;
float screenRatio = (float)screen.w / (float)screen.h;
int screenWidth;
int screenHeight;
SDL_GetWindowSize(window, &screenWidth, &screenHeight);
float screenRatio = (float)screenWidth / (float)screenHeight;

glClearColor(0.0f,0.0f,0.0f,1.0f);
glViewport(0,0,screen.w,screen.h);
glViewport(0,0,screenWidth,screenHeight);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
Expand Down Expand Up @@ -430,7 +443,7 @@ int main(int argc, char *argv[])
particleSystem->renderParticles();
SPK::GL::GLRenderer::restoreGLStates();

SDL_GL_SwapBuffers();
SDL_GL_SwapWindow(window);

// Computes delta time
clock_t currentTick = clock();
Expand All @@ -446,8 +459,9 @@ int main(int argc, char *argv[])

SDL_Quit();

#ifdef _WIN32
system("pause");

#endif
return 0;
}

Expand Down
49 changes: 31 additions & 18 deletions demos/src/SPKExplosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@
#if defined(WIN32) || defined(_WIN32)
#include <windows.h>
#endif

#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif

#include <SDL.h>
#include <SPARK.h>
Expand Down Expand Up @@ -171,7 +177,7 @@ void drawBoundingBox(const SPK::System& system)
}

// Renders the scene
void render()
void render(SDL_Window* window)
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Expand All @@ -194,7 +200,7 @@ void render()
(*it)->renderParticles();
}

SDL_GL_SwapBuffers();
SDL_GL_SwapWindow(window);
}

// Creates the base system and returns its ID
Expand Down Expand Up @@ -457,24 +463,29 @@ int main(int argc, char *argv[])

// inits SDL
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("SPARK Explosion demo",NULL);

SDL_Window* window = SDL_CreateWindow("SPARK Explosion demo",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
0, 0,
SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_OPENGL);

SDL_GL_CreateContext(window);

SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);

// vsync
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,0);
SDL_GL_SetSwapInterval(0);

SDL_SetVideoMode(0,0,32,SDL_OPENGL | SDL_FULLSCREEN);
SDL_ShowCursor(0);

SDL_Surface& screen = *SDL_GetVideoSurface();
SDL_SetRelativeMouseMode(SDL_TRUE);

// inits openGL
screenWidth = screen.w;
screenHeight = screen.h;
screenRatio = (float)screen.w / (float)screen.h;
SDL_GetWindowSize(window, &screenWidth, &screenHeight);
screenRatio = (float)screenWidth / (float)screenHeight;

glClearColor(0.0f,0.0f,0.0f,1.0f);
glViewport(0,0,screen.w,screen.h);
glViewport(0,0,screenWidth,screenHeight);

// Loads particle texture
GLuint textureExplosion;
Expand Down Expand Up @@ -553,12 +564,12 @@ int main(int argc, char *argv[])
}

// Zoom in and out
if (event.type == SDL_MOUSEBUTTONDOWN)
if(event.type == SDL_MOUSEWHEEL)
{
if (event.button.button == SDL_BUTTON_WHEELDOWN)
camPosZ = min(10.0f,camPosZ + 0.5f);
if (event.button.button == SDL_BUTTON_WHEELUP)
camPosZ = max(0.5f,camPosZ - 0.5f);
if (event.wheel.y > 0)
camPosZ = fmax(0.5f,camPosZ - 0.5f);
if (event.wheel.y < 0)
camPosZ = fmax(0.5f,camPosZ - 0.5f);
}

if ((event.type == SDL_KEYDOWN)&&(event.key.keysym.sym == SDLK_F2))
Expand Down Expand Up @@ -611,7 +622,7 @@ int main(int argc, char *argv[])
}

// Renders scene
render();
render(window);

// Computes delta time
int time = SDL_GetTicks();
Expand All @@ -633,7 +644,9 @@ int main(int argc, char *argv[])

SDL_Quit();

#ifdef _WIN32
system("pause"); // Waits for the user to close the console
#endif

return 0;
}
}
36 changes: 25 additions & 11 deletions demos/src/SPKFlakes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@
#if defined(WIN32) || defined(_WIN32)
#include <windows.h>
#endif

#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif

#include <SDL.h>
#include <SPARK.h>
Expand Down Expand Up @@ -110,24 +116,32 @@ int main(int argc, char *argv[])
{
// Inits SDL
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("SPARK Flakes Demo",NULL);

SDL_Window* window = SDL_CreateWindow("SPARK Flakes Demo",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
0, 0,
SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_OPENGL);

SDL_GL_CreateContext(window);


SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);

// vsync
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,0);
SDL_GL_SetSwapInterval(0);

SDL_SetVideoMode(0,0,32,SDL_OPENGL | SDL_FULLSCREEN);
SDL_ShowCursor(0);

SDL_Surface& screen = *SDL_GetVideoSurface();
SDL_SetRelativeMouseMode(SDL_TRUE);

// Inits openGL
int screenWidth = screen.w;
int screenHeight = screen.h;
float screenRatio = (float)screen.w / (float)screen.h;
int screenWidth;
int screenHeight;
SDL_GetWindowSize(window, &screenWidth, &screenHeight);
float screenRatio = (float)screenWidth / (float)screenHeight;

glClearColor(0.0f,0.0f,0.0f,1.0f);
glViewport(0,0,screen.w,screen.h);
glViewport(0,0,screenWidth,screenHeight);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
Expand Down Expand Up @@ -298,7 +312,7 @@ int main(int argc, char *argv[])
particleSystem->renderParticles();
SPK::GL::GLRenderer::restoreGLStates();

SDL_GL_SwapBuffers();
SDL_GL_SwapWindow(window);

// Computes delta time
clock_t currentTick = clock();
Expand All @@ -315,4 +329,4 @@ int main(int argc, char *argv[])
SDL_Quit();

return 0;
}
}
35 changes: 25 additions & 10 deletions demos/src/SPKTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@
#if defined(WIN32) || defined(_WIN32)
#include <windows.h>
#endif

#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif

#include <SDL.h>
#include <SPARK.h>
Expand Down Expand Up @@ -157,22 +163,28 @@ void drawBoundingBox(const SPK::System& system)
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("SPARK 2 test",NULL);
SDL_Window* window = SDL_CreateWindow("SPARK 2 test",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
800,
600,
SDL_WINDOW_OPENGL);

SDL_GL_CreateContext(window);

SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); // double buffering

// vsync
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,0);
SDL_GL_SetSwapInterval(0);

// AA
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,4);

SDL_SetVideoMode(800,600,32,SDL_OPENGL);

SDL_Surface& screen = *SDL_GetVideoSurface();
int screenWidth = screen.w;
int screenHeight = screen.h;
float screenRatio = (float)screen.w / (float)screen.h;
int screenWidth;
int screenHeight;
SDL_GetWindowSize(window, &screenWidth, &screenHeight);
float screenRatio = (float)screenWidth / (float)screenHeight;

// Loads particle texture
GLuint textureParticle;
Expand Down Expand Up @@ -286,7 +298,7 @@ int main(int argc, char *argv[])
system->renderParticles();
SPK::GL::GLRenderer::restoreGLStates();

SDL_GL_SwapBuffers();
SDL_GL_SwapWindow(window);

clock_t currentTick = clock();
deltaTime = (float)(currentTick - frameFPS.back()) / CLOCKS_PER_SEC;
Expand Down Expand Up @@ -330,7 +342,10 @@ int main(int argc, char *argv[])
SPK_DUMP_MEMORY

SDL_Quit();

#ifdef _WIN32
std::system("pause");
#endif

return 0;
}
}
6 changes: 3 additions & 3 deletions demos/src/SPKTestIrrlicht.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int main(int argc, char *argv[])
SPK::Ref<SPK::IRR::IRRQuadRenderer> quadRenderer = SPK::IRR::IRRQuadRenderer::create(device);
quadRenderer->setBlendMode(SPK::BLEND_MODE_ADD);
quadRenderer->enableRenderingOption(SPK::RENDERING_OPTION_DEPTH_WRITE,false);
quadRenderer->setTexture(driver->getTexture("res\\flare.bmp"));
quadRenderer->setTexture(driver->getTexture("res/flare.bmp"));
quadRenderer->setTexturingMode(SPK::TEXTURE_MODE_2D);

SPK::Ref<SPK::Emitter> emitter1 = SPK::RandomEmitter::create(SPK::Point::create());
Expand Down Expand Up @@ -165,7 +165,7 @@ int main(int argc, char *argv[])
// Renders scene
smgr->drawAll();

irr::core::stringw infos; infos+="FPS: "; infos+=driver->getFPS(); infos+=" - Nb Particles: "; infos+=system->getNbParticles();
irr::core::stringw infos; infos+="FPS: "; infos+=driver->getFPS(); infos+=" - Nb Particles: "; infos+=static_cast<unsigned int>(system->getNbParticles());
guienv->getBuiltInFont()->draw(infos.c_str(),irr::core::rect<irr::s32>(0,0,170,20),irr::video::SColor(255,255,255,255));

driver->endScene();
Expand All @@ -177,4 +177,4 @@ int main(int argc, char *argv[])
SPK_DUMP_MEMORY

return 0;
}
}
4 changes: 2 additions & 2 deletions demos/src/SPKTestIrrlicht_Controllers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ int main(int argc, char *argv[])
SPK::Ref<SPK::IRR::IRRQuadRenderer> quadRenderer = SPK::IRR::IRRQuadRenderer::create(device);
quadRenderer->setBlendMode(SPK::BLEND_MODE_ADD);
quadRenderer->enableRenderingOption(SPK::RENDERING_OPTION_DEPTH_WRITE,false);
quadRenderer->setTexture(driver->getTexture("res\\flare.bmp"));
quadRenderer->setTexture(driver->getTexture("res/flare.bmp"));
quadRenderer->setTexturingMode(SPK::TEXTURE_MODE_2D);

SPK::Ref<SPK::Point> emitpt = SPK::Point::create();
Expand Down Expand Up @@ -247,7 +247,7 @@ int main(int argc, char *argv[])
// Renders scene
smgr->drawAll();

irr::core::stringw infos; infos+="FPS: "; infos+=driver->getFPS(); infos+=" - Nb Particles: "; infos+=system->getNbParticles();
irr::core::stringw infos; infos+="FPS: "; infos+=driver->getFPS(); infos+=" - Nb Particles: "; infos+=static_cast<unsigned int>(system->getNbParticles());
guienv->getBuiltInFont()->draw(infos.c_str(),irr::core::rect<irr::s32>(0,0,170,20),irr::video::SColor(255,255,255,255));

driver->endScene();
Expand Down