Loading a texture in SFML fails with no message as to why - sfml

I have been following the tutorials on SFML and tried to load a texture using the following code
sf::Texture texture;
if (!texture.loadFromFile("image.png"))
{
return sf::Texture();
}
This fails to load the texture, the sprite is white which is not the colour of my sprite..

As taken directly from the graphics-sprite tutorial on the SFML website
"The loadFromFile function sometimes fails with no obvious reason. First, check the error message printed by SFML in the
standard output (check the console). If the message is unable to open file, make sure that the working directory (which is the
directory any file path will be interpreted relatively to) is what you think it is: when you run the application from the explorer, the
working directory is the executable folder, but when you launch your program from your IDE (Visual Studio, Code::Blocks, ...) the
working directory is sometimes set to the project directory instead. This can generally be changed easily in the project settings."
Therefore ensure your image is firstly named correctly and secondendly make sure it is in the correct folder i.e. in your working directory.
Also if the texture fails to load instead of returning an empty sprite you could report an error to the console and then throw an exception.
This way you will be told the sprite does not load correctly and the program will have to handle the exception otherwise it will be terminated. This way no sprite in the game should
have a white texture unless intentional
Something like this:
sf::Texture texture;
if (!texture.loadFromFile("image.png"))
{
throw std::runtime_error("Could not load image.png");
}

Loading a PNG ? Make it 8bit. Other png formats can be loaded but are always displayed as white squares.

Related

where to find code blocks Sfml image resources

I'm using code blocks with sfml and besides it looking ugly, I'm not sure where to store images. I have to select the exact path by putting it in the project folder in the file system. How do i add images?
Say that your project was in
C:\Users\Me\Documents\MyProj
Then then putting the images in this folder would make them visible to SFML/codeblocks when using only the image name.
If you had an image called image.png then the full path to the image would be
C:\Users\Me\Documents\MyProj\image.png
To get the image into your program you must include
#include <SFML/Graphics.hpp>
And create a texture
sf::Texture Texture1;
And then you can assign this image like
Texture1.loadFromFile("C:\Users\Me\Documents\MyProj\image.png"); //Full path
Texture1.loadFromFile("image.png"); //Relative path
Next you create a sprite
sf::Sprite MySprite
And assign the texture to it
MySprite.setTexture(Texture1);
Finally to draw in the window use
window.draw(MySprite);

SFML 1.6 - Blured text [duplicate]

I'm using SFML 1.6 to make a small game, and I need to display some text, so I use the sf::String class. The problem is, when I increase the size to 96pt, the edges appear a little blurry. When I increase the size of text in Microsoft Word though, it appears very clean and has crisp edges. Is there a way to do that with SFML?
Looking at the SFML sources, it appears that it is using the embedded Arial font. Yes, it can also load the .ttf font file, but I guess you didn't load it yet.
So the problem is tht SFML tries to scale the fixed-size bitmap when you are rendering the text.
To get rid of the aliasing try following this sample http://www.sfml-dev.org/tutorials/1.4/graphics-fonts.php and load the .ttf manually.

Large text appears blurry

I'm using SFML 1.6 to make a small game, and I need to display some text, so I use the sf::String class. The problem is, when I increase the size to 96pt, the edges appear a little blurry. When I increase the size of text in Microsoft Word though, it appears very clean and has crisp edges. Is there a way to do that with SFML?
Looking at the SFML sources, it appears that it is using the embedded Arial font. Yes, it can also load the .ttf font file, but I guess you didn't load it yet.
So the problem is tht SFML tries to scale the fixed-size bitmap when you are rendering the text.
To get rid of the aliasing try following this sample http://www.sfml-dev.org/tutorials/1.4/graphics-fonts.php and load the .ttf manually.

How to get an off-screen plain surface from 'normal' IDirect3D9Surface

I'm working on a media player with Media Foundation. I'm trying to use post processing with DXVA-HD. However, when I try to do a VideoProcessBltHD using the HD device, it fails with E_INVALIDARGS. What I doubt is it is not somehow working correctly with the ID39Surface I'm providing as input. I'm getting the input surface from 'IMFMediaBuffer' (which I get from reading a sample from the SourceReader).
I'm extracting the surface as follows:
CHECK_HR (hr = MFGetService( video_buffer, MR_BUFFER_SERVICE, __uuidof(IDirect3DSurface9), (void**)&pSurface) );
However, in the DXVA-HD example on MSDN, the VideoProcessBltHD works fine.
Whereas the IDirect3DSurface9 surface in the sample code is an off screen plain surface.
How do I pass 'my surface'(which has the video data) as an off screen plain surface to the video processor and the get 'blt-operation' succeed?
Any help would be appreciated.
Thanks
Mots
I would suggest installing full DirectX SDK, switch runtime library to debug mode in DirectX Control Pannel, turn full validation, break on error and run your app in debug mode. This way, you will get DirectX human readable error description.

freeglut's glutStrokeString giving a "stroke font not found error"

I am trying to use glutStrokeString using freeglut.
The program runs fine up to the point it has to call glutStrokeString, then it outputs the console freeglut stroke font not found.
Any idea why?
GLUT_BITMAP_HELVETICA_18, as the name suggests, is a bitmap font. You can't use them with the Stroke rendering commands. So if you want to use that font, you have to use glutBitmapString.
FreeGLUT comes with two stroke fonts: GLUT_STROKE_ROMAN and GLUT_STROKE_MONO_ROMAN. So if you want to use the stroke commands to render the fonts, you have to use one of those kinds of fonts.
Just check out the file, gluit/freeglut_font.c, in your glut source code, contains everything you need to know, Also check fghFontByID() and fghStrokeByID() which are actually used to computed the font id for both the functions that is glutBitmapString() & glutStrokeString()
or check out this