1
SFML wiki / SFML CEGUI tutorial - updated code
« on: January 05, 2012, 06:20:19 am »
I'm personally interested in it being uploaded as well. I'm trying to integrate CEGUI into SFML2 as well.
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.
VideoMode videoMode = sf::VideoMode::GetDesktopMode();
float aspectRatio = (float)videoMode.Width/(float)videoMode.Height;
float screenSize = 380;
scene->view = new sf::View(sf::FloatRect(0, 0, screenSize, screenSize/aspectRatio));
/*
* RenderSystem.h
* GameEngine
*
* Created by Jesse Werner on 1/30/11.
* Copyright 2011 none. All rights reserved.
*
*/
#pragma once
#include <SFML/Graphics.hpp>
#include <vector>
#include "TileLayer.h"
using namespace sf;
using namespace std;
class RenderSystem
{
public:
RenderSystem(RenderWindow *myRenderWindow, float myRatio);
RenderWindow *renderWindow;
vector<Sprite*> renderList;
vector<TileLayer*> tileLayers;
float PTM_RATIO;
void render(View *view);
};
/*
* RenderSystem.cpp
* GameEngine
*
* Created by Jesse Werner on 1/30/11.
* Copyright 2011 none. All rights reserved.
*
*/
#include <SFML/Graphics.hpp>
#include "RenderSystem.h"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace sf;
RenderSystem::RenderSystem(RenderWindow *myRenderWindow, float myRatio)
{
renderWindow = myRenderWindow;
PTM_RATIO = myRatio;
}
void RenderSystem::render(View *view)
{
//printf("view center: %f,%f \n",view->GetCenter().x, view->GetCenter().y);
//printf("view extents: %f,%f \n",view->GetHalfSize().x, view->GetHalfSize().y);
for(int i = 0; i<tileLayers.size(); i += 1)
{
for(int j = 0; j<tileLayers[i]->tiles.size(); j++)
{
Tile* tile = tileLayers[i]->tiles[j];
//printf("(%f,%f) \n",tile->x * PTM_RATIO, tile->y * PTM_RATIO);
if(tile->x*PTM_RATIO - view->GetCenter().x < view->GetHalfSize().x )
{
if(tile->x*PTM_RATIO - view->GetCenter().x > -view->GetHalfSize().x-1*PTM_RATIO)
{
if(tile->y*PTM_RATIO - view->GetCenter().y < view->GetHalfSize().y )
{
if(tile->y*PTM_RATIO - view->GetCenter().y > -view->GetHalfSize().y-1*PTM_RATIO )
{
Image *src = tileLayers[i]->image;
int left = tile->tx;
int right = left + 16;
int top = tile->ty;
int bottom = tile->ty + 16;
Sprite sprite;
sprite.SetImage(*src);
sprite.SetSubRect(IntRect( left, top, right, bottom));
sprite.SetX(tile->x*PTM_RATIO);
sprite.SetY(tile->y*PTM_RATIO);
renderWindow->Draw(sprite);
}
}
}
}
}
}
for(int i = 0; i<renderList.size(); i++)
{
renderWindow->Draw(*renderList[i]);
}
renderList.clear();
}
/*
* RenderSystem.h
* GameEngine
*
* Created by Jesse Werner on 1/30/11.
* Copyright 2011 none. All rights reserved.
*
*/
#pragma once
#include <SFML/Graphics.hpp>
#include <vector>
#include "TileLayer.h"
using namespace sf;
using namespace std;
class RenderSystem
{
public:
RenderSystem(RenderWindow *myRenderWindow, float myRatio);
RenderWindow *renderWindow;
vector<Sprite*> renderList;
vector<TileLayer*> tileLayers;
float PTM_RATIO;
void render(View *view);
};
/*
* RenderSystem.cpp
* GameEngine
*
* Created by Jesse Werner on 1/30/11.
* Copyright 2011 none. All rights reserved.
*
*/
#include <SFML/Graphics.hpp>
#include "RenderSystem.h"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace sf;
RenderSystem::RenderSystem(RenderWindow *myRenderWindow, float myRatio)
{
renderWindow = myRenderWindow;
PTM_RATIO = myRatio;
}
void RenderSystem::render(View *view)
{
//printf("view center: %f,%f \n",view->GetOrigin().x, view->GetOrigin().y);
//printf("view extents: %f,%f \n",view->GetSize()/2().x, view->GetSize()/2().y);
for(int i = 0; i<tileLayers.size(); i += 1)
{
for(int j = 0; j<tileLayers[i]->tiles.size(); j++)
{
Tile* tile = tileLayers[i]->tiles[j];
//printf("(%f,%f) \n",tile->x * PTM_RATIO, tile->y * PTM_RATIO);
if(tile->x*PTM_RATIO - view->GetCenter().x < view->GetSize().x/2.0 )
{
if(tile->x*PTM_RATIO - view->GetCenter().x > -view->GetSize().x/2.0-1*PTM_RATIO)
{
if(tile->y*PTM_RATIO - view->GetCenter().y < view->GetSize().y/2.0 )
{
if(tile->y*PTM_RATIO - view->GetCenter().y > -view->GetSize().y/2.0-1*PTM_RATIO )
{
Image *src = tileLayers[i]->image;
int left = tile->tx;
int right = left + 16;
int top = tile->ty;
int bottom = tile->ty + 16;
Sprite sprite;
sprite.SetImage(*src);
sprite.SetSubRect(IntRect( left, top, right, bottom));
sprite.SetX(tile->x*PTM_RATIO);
sprite.SetY(tile->y*PTM_RATIO);
renderWindow->Draw(sprite);
}
}
}
}
}
}
for(int i = 0; i<renderList.size(); i++)
{
renderWindow->Draw(*renderList[i]);
}
renderList.clear();
}
sprite class
getcenter ---> getorigin
setcenter ---> setorigin
view class
gethalfsize ---> getsize()/2
vectorf's must be redone because no more halfsize
string class
no longer has setposition function
renderwindow class
enable useverticalsync to EnableVerticalSync
windowsettings to contextsettings class
ensure defining SFML_STATIC