Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Topics - JCSopko

Pages: [1]
1
Window / [SFML2] Retrieving screen aspect ratio and applying to view
« on: March 14, 2011, 06:45:10 pm »
I was unsure whether to put this here or in the Graphics forum but basically I'm trying to set my camera view to a size of an equal aspect ratio of the monitor.

Code: [Select]
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));


Hypothetically this should work with any given screenSize but I'm still getting pretty profound distortion with certain numbers (such as 800 on a 16:9 monitor).

Is there a better way to control the field of view while still keeping the proper aspect ratio (no stretching) no matter what monitor you're on?

Thanks!

2
Graphics / SFML 1.6 to SFML 2.0 porting failure
« on: February 27, 2011, 02:43:55 am »
While trying to port a game engine to SFML2 originally made in 1.6 I've run into some problems. There are no compile errors but some tiles are not rendered and are instead left completely black. Here is the original code (works perfectly), the 2.0 port, and my typed out notes as I was porting. If any clarification is needed to help out let me know. Thanks for your time!

SFML 1.6 (Works perfectly)
header
Code: [Select]
/*
 *  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);

};



SFML 1.6 (works perfectly) cpp
Code: [Select]
/*
 *  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();
}


SFML2 (does not work)
header
Code: [Select]
/*
 *  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);

};


SFML2 (does not work)
cpp
Code: [Select]
/*
 *  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();
}




Changes made (sorry for lack of readability)
Code: [Select]

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

3
General / SFML2 Static Lib Linker Error
« on: November 08, 2010, 01:06:46 am »
I saw there were a few others of these but the proposed solutions didn't work.

I've tried downloading, compiling SFML2 with cmake, and compiling SFML2 three times with no results. I get the libraries but end up getting these linker errors when using the static debug libraries:

1>Game.obj : warning LNK4217: locally defined symbol ??0RenderWindow@sf@@QAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@KABUContextSettings@1@@Z (public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned long,struct sf::ContextSettings const &)) imported in function "public: __thiscall Game::Game(void)" (??0Game@@QAE@XZ)
1>Game.obj : warning LNK4217: locally defined symbol ??0VideoMode@sf@@QAE@III@Z (public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)) imported in function "public: __thiscall Game::Game(void)" (??0Game@@QAE@XZ)
1>Game.obj : warning LNK4217: locally defined symbol ??1RenderWindow@sf@@UAE@XZ (public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)) imported in function "public: virtual void * __thiscall sf::RenderWindow::`scalar deleting destructor'(unsigned int)" (??_GRenderWindow@sf@@UAEPAXI@Z)
1>Game.obj : warning LNK4217: locally defined symbol ?Display@Window@sf@@QAEXXZ (public: void __thiscall sf::Window::Display(void)) imported in function "public: void __thiscall Game::draw(void)" (?draw@Game@@QAEXXZ)
1>Game.obj : warning LNK4217: locally defined symbol ?Draw@RenderTarget@sf@@QAEXABVDrawable@2@@Z (public: void __thiscall sf::RenderTarget::Draw(class sf::Drawable const &)) imported in function "public: void __thiscall Game::draw(void)" (?draw@Game@@QAEXXZ)
1>Game.obj : warning LNK4217: locally defined symbol ?Clear@RenderTarget@sf@@QAEXABVColor@2@@Z (public: void __thiscall sf::RenderTarget::Clear(class sf::Color const &)) imported in function "public: void __thiscall Game::draw(void)" (?draw@Game@@QAEXXZ)
1>Game.obj : warning LNK4217: locally defined symbol ??0Color@sf@@QAE@EEEE@Z (public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)) imported in function "public: void __thiscall Game::draw(void)" (?draw@Game@@QAEXXZ)
1>GameObject.obj : warning LNK4049: locally defined symbol ??0Color@sf@@QAE@EEEE@Z (public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)) imported
1>GameObject.obj : warning LNK4217: locally defined symbol ??1Image@sf@@QAE@XZ (public: __thiscall sf::Image::~Image(void)) imported in function "public: __thiscall GameObject::GameObject(struct b2Vec2,struct b2Vec2)" (??0GameObject@@QAE@Ub2Vec2@@0@Z)
1>GameObject.obj : warning LNK4217: locally defined symbol ?SetColor@Drawable@sf@@QAEXABVColor@2@@Z (public: void __thiscall sf::Drawable::SetColor(class sf::Color const &)) imported in function "public: __thiscall GameObject::GameObject(struct b2Vec2,struct b2Vec2)" (??0GameObject@@QAE@Ub2Vec2@@0@Z)
1>GameObject.obj : warning LNK4217: locally defined symbol ?SetPosition@Drawable@sf@@QAEXMM@Z (public: void __thiscall sf::Drawable::SetPosition(float,float)) imported in function "public: __thiscall GameObject::GameObject(struct b2Vec2,struct b2Vec2)" (??0GameObject@@QAE@Ub2Vec2@@0@Z)
1>GameObject.obj : warning LNK4217: locally defined symbol ?SetOrigin@Drawable@sf@@QAEXMM@Z (public: void __thiscall sf::Drawable::SetOrigin(float,float)) imported in function "public: __thiscall GameObject::GameObject(struct b2Vec2,struct b2Vec2)" (??0GameObject@@QAE@Ub2Vec2@@0@Z)
1>TestGameObject.obj : warning LNK4217: locally defined symbol ?SetOrigin@Drawable@sf@@QAEXMM@Z (public: void __thiscall sf::Drawable::SetOrigin(float,float)) imported in function "public: __thiscall TestGameObject::TestGameObject(void)" (??0TestGameObject@@QAE@XZ)
1>GameObject.obj : warning LNK4217: locally defined symbol ?Create@Image@sf@@QAE_NIIABVColor@2@@Z (public: bool __thiscall sf::Image::Create(unsigned int,unsigned int,class sf::Color const &)) imported in function "public: __thiscall GameObject::GameObject(struct b2Vec2,struct b2Vec2)" (??0GameObject@@QAE@Ub2Vec2@@0@Z)
1>GameObject.obj : warning LNK4217: locally defined symbol ??0Image@sf@@QAE@XZ (public: __thiscall sf::Image::Image(void)) imported in function "public: __thiscall GameObject::GameObject(struct b2Vec2,struct b2Vec2)" (??0GameObject@@QAE@Ub2Vec2@@0@Z)
1>TestGameObject.obj : warning LNK4217: locally defined symbol ??0Image@sf@@QAE@XZ (public: __thiscall sf::Image::Image(void)) imported in function __ehhandler$??0TestGameObject@@QAE@XZ
1>GameObject.obj : warning LNK4217: locally defined symbol ?SetRotation@Drawable@sf@@QAEXM@Z (public: void __thiscall sf::Drawable::SetRotation(float)) imported in function "public: virtual void __thiscall GameObject::update(void)" (?update@GameObject@@UAEXXZ)
1>TestGameObject.obj : warning LNK4217: locally defined symbol ?LoadFromFile@Image@sf@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z (public: bool __thiscall sf::Image::LoadFromFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported in function "public: __thiscall TestGameObject::TestGameObject(void)" (??0TestGameObject@@QAE@XZ)
1>Game.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::Sprite::~Sprite(void)" (__imp_??1Sprite@sf@@UAE@XZ) referenced in function "public: void __thiscall Game::loadLevel(char *)" (?loadLevel@Game@@QAEXPAD@Z)
1>GameObject.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::Sprite::~Sprite(void)" (__imp_??1Sprite@sf@@UAE@XZ)
1>Game.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Sprite::Sprite(void)" (__imp_??0Sprite@sf@@QAE@XZ) referenced in function "public: void __thiscall Game::loadLevel(char *)" (?loadLevel@Game@@QAEXPAD@Z)
1>GameObject.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Sprite::Sprite(void)" (__imp_??0Sprite@sf@@QAE@XZ)
1>GameObject.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Sprite::SetImage(class sf::Image const &,bool)" (__imp_?SetImage@Sprite@sf@@QAEXABVImage@2@_N@Z) referenced in function "public: __thiscall GameObject::GameObject(struct b2Vec2,struct b2Vec2)" (??0GameObject@@QAE@Ub2Vec2@@0@Z)
1>TestGameObject.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Sprite::SetImage(class sf::Image const &,bool)" (__imp_?SetImage@Sprite@sf@@QAEXABVImage@2@_N@Z)
1>GameObject.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class sf::Sprite & __thiscall sf::Sprite::operator=(class sf::Sprite const &)" (__imp_??4Sprite@sf@@QAEAAV01@ABV01@@Z) referenced in function "public: __thiscall GameObject::GameObject(struct b2Vec2,struct b2Vec2)" (??0GameObject@@QAE@Ub2Vec2@@0@Z)
1>C:\Users\Joe\Desktop\GameObjectClass\Windows\build\Static Debug\Game1.exe : fatal error LNK1120: 4 unresolved externals
1>
1>Build FAILED.

Any suggestions?


P.S. Code currently works with Dynamic Debug so it's not the code.

Thanks!

4
General discussions / SFML Cross-Platform Stability?
« on: November 06, 2010, 08:19:01 pm »
I've used SFML in the past and fell in love with its simplicity and versatility but I'm concerned to move forward with building my own framework with it because I'm worried of Mac OS support not being solid enough.

The reason I want to use a framework is so I don't have to worry about what the framework does, I don't want to commit to using SFML if I'm going to have to play around with its insides to fix bugs for Mac every now and then.

Has anyone picked up the Mac OS port to ensure better future stability?

If not does anyone have any suggestions for a library with strong Win/Mac/Linux support that's similar to SFML?

My only alternative option right now is Allegro.





TL;DR.

Need high level C++ 2d graphics library with solid support for Win/Mac/Linux. Recommend please.

5
Window / Execute Code on Key Release?
« on: June 30, 2010, 05:54:03 pm »
I've been looking around the forums and the documentation but have been unable to find a way to execute a string of code on the release of a key press with SFML 1.6. Can someone help me out or point me in the right direction? Thanks.

Regards,
Joe

Pages: [1]