1
Graphics / [solved] splitscreen?
« on: July 24, 2009, 08:29:03 am »
What a shame... Why wasn't Visual Studio even casting a warning?!?
Anyway, it works now . Thanks!
Anyway, it works now . Thanks!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
#include "cGame.h"
int main()
{
cGame game;
game.run();
return 1;
}
#ifndef C_GAME_H
#define C_GAME_H
#include <SFML/Graphics.hpp>
//Consts
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 800;
const int GAME_FPS = 60;
class cGame
{
public:
cGame(void);
~cGame(void);
void run(void);
private:
bool isRunning;
sf::RenderWindow *Display;
inline void SplitOn(const sf::RenderWindow& Window, const sf::Rect<int>& Zone);
inline void SplitOff();
void handleGameEvents(void);
};
#endif
#include "cGame.h"
cGame::cGame(void)
{
Display = new sf::RenderWindow(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32),"MoonSpire",sf::Style::Close);
Display->SetFramerateLimit(GAME_FPS);
isRunning = true;
}
cGame::~cGame(void)
{
}
inline void cGame::SplitOn(const sf::RenderWindow& Window, const sf::Rect<int>& Zone)
{
glEnable (GL_SCISSOR_TEST);
glScissor(Zone.Left, Window.GetHeight() - Zone.Bottom, Zone.GetWidth(), Zone.GetHeight());
}
inline void cGame::SplitOff()
{
glDisable (GL_SCISSOR_TEST);
}
void cGame::run(void)
{
char runLvl = 2;
// Start game loop
while (isRunning)
{
switch(runLvl)
{
// Menulvl
case 0:
break;
// Create gamestuff
case 1:
break;
// Load game
case 2:
// draw first half of screen
Display->Clear();
sf::Sprite Test;
Test.Resize(20, 40); // "vertical block"
for (int y=0; y<10; y++)
{
for(int x=0; x<10; x++)
{
Test.SetPosition(x*70 + 50, y*50 + 70);
Display->Draw(Test);
}
}
// draw second half of screen
sf::Rect<int> Zone(SCREEN_WIDTH/2, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
SplitOn(Display, Zone);
Display->Clear();
sf::Sprite Test2;
Test2.Resize(40, 20); // "horizontal block"
for (int y=0; y<10; y++)
{
for(int x=0; x<10; x++)
{
Test2.SetPosition(x*70 + 50, y*50 + 70);
Display->Draw(Test2);
}
}
Display->Display();
handleGameEvents();
SplitOff();
break;
}
}
}
void cGame::handleGameEvents(void)
{
sf::Event Event;
while (Display->GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
{
isRunning = false;
break;
}
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
{
isRunning = false;
break;
}
}
}