I am trying to learn SFML with C++, and tried to just get something on the screen.
First I tried loading an image and attaching it to a sprite and drawing it, but nothing appeared. I resorted to just a green rectangle, but even that won't display.
What have I done wrong?
[code]#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow App( sf::VideoMode ( 800, 600, 32 ), "Hexagon Puzzle Thing" );
while( App.IsOpened() )
{
sf::Event Event;
while( App.GetEvent( Event ))
{
if( Event.Type == sf::Event::Closed )
App.Close();
}
App.Draw( sf::Shape::Rectangle( 350, 200, 600, 350, sf::Color::Green ));
App.Display();
}
return EXIT_SUCCESS;
}[/code]
I have these libraries included in the "Additional dependencies" part in linker input settings:
[code]kernel32.lib;
user32.lib;
gdi32.lib;
winspool.lib;
comdlg32.lib;
advapi32.lib;
shell32.lib;
ole32.lib;
oleaut32.lib;
uuid.lib;
odbc32.lib;
odbccp32.lib;
sfml-main.lib;
sfml-system.lib;
sfml-window.lib;
sfml-graphics.lib;
OpenGL32.lib;
GLu32.lib;
%(AdditionalDependencies)[/code]
[editline]10:09PM[/editline]
The window produced is completely black. Also, using "App.Clear()" causes this error:
[code]First-chance exception at 0x0100a800 in Concrete.exe: 0xC0000005: Access violation.
A buffer overrun has occurred in Concrete.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.
For more details please see Help topic 'How to debug Buffer Overrun Issues'.[/code]
-Re-edit-
remove OpenGL32.lib; GLu32.lib; ?
I was kind of confused because you also put the inherited values there
Works for me:
[media]http://img705.imageshack.us/img705/7558/worksk.jpg[/media]
[QUOTE=ZomBuster;19201408]-Re-edit-
remove OpenGL32.lib; GLu32.lib; ?
I was kind of confused because you also put the inherited values there[/QUOTE]
Ok, done that but same result :(. I added them when I was testing out SFML's openGL stuff, it didn't work until I added that. I got it drawing with OpenGL but not the SFML built in stuff.
[editline]10:33PM[/editline]
[QUOTE=NullPoint;19201455]Works for me:
[media]http://img705.imageshack.us/img705/7558/worksk.jpg[/media][/QUOTE]
Can you tell me how exactly you set up that project?
[editline]10:34PM[/editline]
May be because I am using VS2010 beta
[QUOTE=Robert64;19201723]Ok, done that but same result :(. I added them when I was testing out SFML's openGL stuff, it didn't work until I added that. I got it drawing with OpenGL but not the SFML built in stuff.
[editline]10:33PM[/editline]
Can you tell me how exactly you set up that project?
[editline]10:34PM[/editline]
May be because I am using VS2010 beta[/QUOTE]
If you want, I can download VS2010 beta and give it a go, I don't mind.
SFML works with VS2010 Beta. Just recompile SFML.
[QUOTE=NullPoint;19201784]If you want, I can download VS2010 beta and give it a go, I don't mind.[/QUOTE]
It's fine, I'll get the express edition of 2008. My school uses 2008 anyway so I may as well get the same as them now, so I can work on stuff there.
[editline]10:38PM[/editline]
[QUOTE=efeX;19201805]SFML works with VS2010 Beta. Just recompile SFML.[/QUOTE]
Ok, I'll try this and report back.
[editline]12:07AM[/editline]
I got Visual Studio 2008 Express C++ instead of compiling SFML myself, because I would have to move to 2008 eventually anyway.
Now I get this when I try and compile:
[code]1>main.obj : error LNK2001: unresolved external symbol "public: static class sf::Color const sf::Color::Cyan" (?Cyan@Color@sf@@2V12@B)
[/code]
Of all the things it would have a problem with...
[editline]12:19AM[/editline]
I used my own colour instead of using a pre-defined one, and it works! I can see it!
But why did it not work with the predefined green?
How did you use it?
[QUOTE=efeX;19203852]How did you use it?[/QUOTE]
My own colour?
[code]sf::Color( 0, 255, 0 )[/code]
No, the code that give you the linker error. Where was it used?
[QUOTE=efeX;19204265]No, the code that give you the linker error. Where was it used?[/QUOTE]
Its the same as the one posted in the OP, with Visual Studio 2008 express and SFML 1.5
[editline]01:32AM[/editline]
I have a new problem:
I have an image loaded as a static var in a class, and I want to set a sprites's image to be that image. This is how I'm doing it (I'm too tired to extract the relevant parts):
[code]//main.cpp
#include <SFML/Graphics.hpp>
#include <iostream>
#include "tile.h"
int main()
{
sf::RenderWindow App( sf::VideoMode( 800, 600, 32 ), "Hexagon Puzzle Thing" );
if( !Tile::LoadImages()) return EXIT_FAILURE;
Tile test_tile( T_ACTIVE );
std::cout << test_tile.pos.x << " " << test_tile.pos.y << "\n";
while( App.IsOpened() )
{
sf::Event Event;
while( App.GetEvent( Event ))
{
if( Event.Type == sf::Event::Closed )
App.Close();
}
test_tile.Draw( App );
App.Display();
}
return EXIT_SUCCESS;
}[/code]
[code]//tile.h
#include <SFML/Graphics.hpp>
#include <iostream>
enum TileStates
{
T_NULL,
T_ACTIVE,
T_BOMB,
T_TESTED,
T_BLOWN
};
class Tile
{
public:
Tile( int initstate );
~Tile( void );
bool Test( void );
void Deactivate( void );
static bool LoadImages( void );
void Draw( sf::RenderWindow &App );
int state;
int x;
int y;
sf::Vector2f pos;
sf::Sprite sprite;
static sf::Image img_tile_back;
static sf::Image img_tile_front;
static sf::Image img_tile_bomb;
static sf::Image img_tile_flag;
private:
static int cur_id;
int id;
};[/code]
[code]//tile.cpp
#include "Tile.h"
int Tile::cur_id = 0;
sf::Image Tile::img_tile_back;
sf::Image Tile::img_tile_front;
sf::Image Tile::img_tile_bomb;
sf::Image Tile::img_tile_flag;
Tile::Tile( int initstate )
{
state = initstate;
id = cur_id;
cur_id ++;
x = ( int ) floor( id / 8.f );
y = id % 8;
pos.x = x * 36.f;
pos.y = ( y * 32.f ) + (( x % 2 ) * 16.f );
sprite.SetImage( img_tile_back );
sprite.SetPosition( pos );
}
Tile::~Tile( void )
{
}
bool Tile::LoadImages( void )
{
if( !img_tile_back.LoadFromFile( "hex_back.png" )) return false;
if( !img_tile_front.LoadFromFile( "hex_overlay.png" )) return false;
if( !img_tile_bomb.LoadFromFile( "hex_skull.png" )) return false;
if( !img_tile_flag.LoadFromFile( "hex_flag.png" )) return false;
return true;
}
bool Tile::Test( void )
{
if( state != T_ACTIVE && state != T_BOMB ) return false;
return true;
}
void Tile::Deactivate( void )
{
if( state == T_ACTIVE ) state = T_NULL;
}
void Tile::Draw( sf::RenderWindow &App )
{
App.Draw( sprite );
}[/code]
It compiles fine, but immediately throws an exception at the line AFTER sprite.SetImage( img_tile_back );. The error I get is
[code]Unhandled exception at 0x1015b824 in HexagonPuzzle.exe: 0xC0000005: Access violation reading location 0x00000004.[/code]
The images have definitely loaded, as I checked to see what their pixels contained with VS2008. What is this error about?
And the error is always thrown a the line after sprite.SetImage( img_tile_back );, no matter what it has in it.
[editline]02:02AM[/editline]
It works in Release mode, but not Debug. Debug uses the dynamic version of the libraries.
Anyway, enough of trying to get it working tonight.
On a side note, if this is just test code it's all good, but you are instantiating a rectangle per frame.
[QUOTE=Xeon06;19205393]On a side note, if this is just test code it's all good, but you are instantiating a rectangle per frame.[/QUOTE]
Yeah it was just a test. I've pretty much got it all working but only in release mode.
It says in the SFML docs that you have to link against the versions of the library with suffix -d for it to work in debug mode.
[QUOTE=TheBoff;19210177]It says in the SFML docs that you have to link against the versions of the library with suffix -d for it to work in debug mode.[/QUOTE]
That's what I am doing.
If you're linking dynamically, you need to #define SFML_DYNAMIC (or something like that) for it to work properly.
[QUOTE=zyxxyz;19212537]If you're linking dynamically, you need to #define SFML_DYNAMIC (or something like that) for it to work properly.[/QUOTE]
Have done.
New problem: I have a screen full of tiles, and drawing them all every game loop would be sluggish. So I draw them all onto an image the size of the window whenever they change, and just draw that single image every game loop.
But drawing that huge ( 800 * 624 ) image onto the screen every loop is slow. Is there a way to do it faster?
Someone was doing the exact same thing in a different thread, see there.
I fixed it by updating my video drivers.
New problem:
I can't draw onto a texture with Image.Copy() with applyAlpha = true if the area being copied onto has 0 alpha (the alpha is inherited for some reason). Any way to counter this without doing it pixel by pixel?
IE if the target has 0 alpha, nothing will be copied onto it.
Sorry, you need to Log In to post a reply to this thread.