Jump to content

  • Log In with Google      Sign In   
  • Create Account

Diath

Member Since 25 Sep 2011
Offline Last Active Aug 28 2013 03:59 AM

Posts I've Made

In Topic: Best format to sell games in?

21 March 2012 - 02:37 PM

Well, just provide both? An installer and the compressed archive and let players choose which they want to use.

In Topic: Trouble uploading file using POST request

21 February 2012 - 09:30 AM

I am not familiar with this but add kind of logging system to your upload.php file and check what does script receive, maybe you're sending something wrong.

In Topic: I can't use SDL_mixer with my favourite IDE

13 February 2012 - 02:12 PM

I went through this problem lately, this works just fine with MinGW. Put SDL_mixer.lib file in your lib directory.

In Topic: [SDL] Problem with text output using SDL_ttf (probably).

26 September 2011 - 01:27 AM

Sorry for the late answer, it's been late evening my time when I made the thread.

So I replaced the "new" method with SDL_CreateRGBSurface and added SDL_FreeSurface in drawText on textSurface. Though, it still doesn't output anything.

This is my current code:
#include "../headers/engine.h"

Engine::Engine()
{
	TTF_Init();
	surface = SDL_CreateRGBSurface(SDL_HWSURFACE, 800, 600, 32, 0, 0, 0, 0);
}

Engine::~Engine()
{
	for(int i = 1; i <= 18; ++i)
		TTF_CloseFont(textFont[i]);

	//SDL_FreeSurface(textSurface);
	SDL_FreeSurface(surface);
}

bool Engine::load()
{
	for(int i = 1; i <= 18; ++i)
	{
		textFont[i] = TTF_OpenFont("./resources/fonts/arial.ttf", i);
		if(!textFont[i])
			return false;
	}

	return true;
}

void Engine::drawText(std::string text, int x, int y, SDL_Color color, int fontSize)
{
	if(fontSize < 1 || fontSize > 18)
		return;

	textSurface = TTF_RenderText_Shaded(textFont[fontSize], text.c_str(), color, {0, 0, 0});
	SDL_Rect pos = {x, y, textSurface->w, textSurface->h};
	SDL_BlitSurface(textSurface, &pos, surface, &pos);
	SDL_FreeSurface(textSurface);
}

PARTNERS