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.

Messages - JAssange

Pages: [1] 2 3 ... 7
Graphics / Texture's LoadFromStream won't load pngs
« on: August 25, 2011, 02:59:19 pm »
Found the problem. I wasn't advancing the current position in the file by the number of bytes read. I'm very surprised that anything was able to load without that... Anyway thanks for the help, your fread call was what made me realize what I was missing.

Graphics / Texture's LoadFromStream won't load pngs
« on: August 25, 2011, 01:43:26 am »
I've been trying to write my own InputStream and testing trying to load png files. I eventually wrote a 'reference stream' which just loads the file as is to make sure it was working, and I discovered it seems loading anything except a png works fine, but I get an invalid header error if I load a png with it. Loading the png file with LoadFromFile works fine but I can't use that as I need a custom stream.
Here is my reference stream that works on everything (Fonts, .tgas, etc.) but not pngs:

Code: [Select]
#pragma once

#include <SFML/Graphics.hpp>

class ReferenceStream : public InputStream {
ReferenceStream(string filename);
virtual Int64 Read(char* data, Int64 size);
    virtual Int64 Seek(Int64 position);
    virtual Int64 Tell();
    virtual Int64 GetSize();
Int64 position;
char* buffer;
Int64 bufferLen;

Code: [Select]

#include "ReferenceStream.h"
#include <fstream>

ReferenceStream::ReferenceStream(string filename) : position(0), buffer(nullptr), bufferLen(-1) {
ifstream file(filename, ios::binary | ios::in);
// [snipped] App-specific error handling
file.seekg(0, ios::end);
bufferLen = (Int64)file.tellg();
file.seekg(0, ios::beg);
buffer = new char[(int)bufferLen];
memset(buffer, 0, sizeof(buffer));
file.read(buffer, bufferLen);

Int64 ReferenceStream::Read(char* data, Int64 size) {
if (position + size > bufferLen) {
size = bufferLen - position;
for (Int64 i = position; i < (position + size); i++) {
data[i-position] = buffer[i];
return size;

Int64 ReferenceStream::Seek(Int64 position) {
this->position = position;
if (position >= bufferLen) {
this->position = bufferLen - 1;
return this->position;

Int64 ReferenceStream::Tell() {
return position;

Int64 ReferenceStream::GetSize() {
return bufferLen;

ReferenceStream::~ReferenceStream() {
delete[] buffer;

If I save the output of reading my full stream manually to a file it creates a valid png file, so a bug in SFML or stbimage is the only thing I can come up with...

Graphics / Rotating Text gives ugly results
« on: August 08, 2011, 11:55:37 am »
Quote from: "Laurent"
It seems to happen with every character. Although I only tested a few. It even happens with sentences, there is always a small dot somewhere around the first character.

This is confusing. Does it happen on every character, or only the first one of the string?

I'm pretty sure he means 'it happens to the first character of the sentence no matter what character that is.'

General / What's wrong with my code ?
« on: August 08, 2011, 12:48:25 am »
Quote from: "OniLink10"
It'd be nice if you gave us a complete and minimal code that recreates the problem, complete meaning it can be compiled on its own, and minimal meaning one file, and only containing code related to the problem.

I assume he's using MFC since he said dialog-based application so he'd likely have to provide the entire solution.

Graphics / anything look wrong with this code?
« on: July 31, 2011, 04:18:13 am »
Iterators are invalid once you modify their container.

Graphics / Blurry Font
« on: July 23, 2011, 06:14:28 pm »
Quote from: "Laurent"
He's just casting a const sf::Image& to a sf::Image&. It's perfectly valid (at least technically).

I think he thought it was casting the Font to an Image.

Graphics / Blurry Font
« on: July 23, 2011, 06:08:55 pm »
Quote from: "Nexus"
You can't meaningfully cast arbitrary types to each other. If you do, you should at least use reinterpret_cast.

Anyway, this code evokes undefined behavior. I can't imagine it actually works. Even if it does right now, it is likely to mess up your whole program in a slightly different situation, not to mention another compiler. You should really not do that unless you like long debug sessions.

Casting away constness isn't, in and of itself, undefined behavior. Because the image GetImage returns isn't fundamentally const, it won't be in Read-Only memory, the Standard explicitly allows this case.

Graphics / Blurry Font
« on: July 23, 2011, 06:05:08 am »
Quote from: "Haikarainen"
i cant figure out how to const_cast the image or fix it otherwise.

Untested, but it compiles:
Code: [Select]
Font* f = MyCustomLoadFontMethod();

General / Sprite::SetCenter() question
« on: July 23, 2011, 05:57:05 am »
That method (at least in SFML2 where it is renamed SetOrigin) has overloads; you can either call it with a vector or two floats. The result of dividing a VectorT by T is a VectorT so you've satisfied an overload.

General / Dynamic Key Binding
« on: July 23, 2011, 05:54:44 am »
GetEvent is now PollEvent and the input system has been revamped. It shouldn't be too hard to convert since that example uses events.

Window / memory leaks in sf::window?
« on: July 15, 2011, 03:31:00 am »
You're dumping memory leaks before the end of the program, so of course there will still be allocated memory. Not to mention that function is just broken in general. Use a proper detector like Valgrind or Rational Purify if you're really worried about it.

Window / SFML 2 Suggestion: QWERTY equivalents
« on: July 13, 2011, 01:22:30 pm »
The easiest way I can think of would just be to have an array where the value at the index of the qwerty key they pressed is the azerty key they pressed. And don't forget about us dvorak users!

Graphics / Get image subrect
« on: July 08, 2011, 03:53:12 am »
You just set the subrect and then draw, it'll draw only the subrect.

General discussions / Centralized resource handling
« on: July 08, 2011, 03:52:04 am »
I made my own that heavily uses templates so it doesn't have separate LoadImage, LoadFont etc messages. The manager 'owns' the resources and won't destroy them unless DestroyResource is called with its handle and no other copies are in use.

Network / Re: VOIP example
« on: July 07, 2011, 01:24:03 pm »
Quote from: "Haikarainen"
No shit sherlock

I was having a hard time judging the skill level of the op from his posts so I just thought I'd clarify.

Pages: [1] 2 3 ... 7