I am having a problem trying to get SDL_ttf to work. Mainly with the color value I can't seem to get the color value set. Here is my code can anyone tell me whats wrong?
Code:
/* main.c - Game startup */
#include <stdio.h>
#include "game.h"
char *title_string = "Game framework version 1.0\n";
int quit = 0;
/* Handle all keyboard events */
void HandleKeyboardEvent(SDL_Event *event){
/* Get a convenience pointer to the structure we will use */
SDL_KeyboardEvent *key=&event->key;
/* Switch based on the key symbol */
switch(key->keysym.sym){
case SDLK_ESCAPE:
quit=1;
printf("Exiting\n");
break;
default:
break;
}
/* Switch based on the type */
/* Realeased or Pressed */
switch(key->type){
case SDL_KEYUP:
case SDL_KEYDOWN:
default:
break;
}
}
char IsMessage(void) {
char message_waiting = 0;
/* Code to check for messages goes here */
if (message_waiting) {
return 1;
} else {
return 0;
}
}
void *GetMessage(void) {
void *message;
/* code to retrieve message from queue goes here */
return message;
}
void ProcessMessage(void *message) {
/* Process the message here */
}
int main(int argc, char **argv) {
void *message;
int i;
SDL_Event event;
SDL_Surface *screen;
SDL_Surface *surface;
SDL_Color colors[256];
SDL_Color *color;
SDL_PixelFormat *fmt;
typedef struct{
SDL_Palette *palette;
Uint8 bitsperpixel;
Uint8 bytesperpixel;
Uint8 Rshift;
Uint8 Gshift;
Uint8 Bshift;
} SDL_PixelFormat;
typedef struct{
Uint8 r;
Uint8 g;
Uint8 b;
Uint8 unused;
} SDL_Color;
color = SDL_MapRGB(fmt, 0xFF, 0xFF, 0xFF);
/* Display game title message */
fprintf(stderr, title_string);
/* Startup code goes here */
/* Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) != 0) {
fprintf(stderr, "SDL Error: %s\n", SDL_GetError());
return 0;
}
atexit(SDL_Quit);
for(i=0;i<256;i++){
colors[i].r=i;
colors[i].g=i;
colors[i].b=i;
}
screen = SDL_SetVideoMode(
800, 600, /* width and height of window */
8, /* 8 bit color depth (256 colors) */
SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN /* video flags */
);
if (screen == NULL) {
fprintf(stderr, "Video error: %s\n", SDL_GetError());
exit(1);
}
SDL_WM_SetCaption(title_string, NULL);
SDL_SetColors(screen, colors, 0, 256);
/* Initialize SDL_ttf */
if(TTF_Init()==-1) {
printf("TTF_Init: %s\n", TTF_GetError());
exit(2);
}
if(!TTF_WasInit() && TTF_Init()==-1) {
printf("TTF_Init: %s\n", TTF_GetError());
exit(1);
}
/* Load a font.ttf file at size 20 */
TTF_Font *font;
font=TTF_OpenFont("electroh.ttf", 20);
if(!font) {
printf("TTF_OpenFont: %s\n", TTF_GetError());
// handle error
}
/* Display the Font */
SDL_Surface *text_surface;
if(!(text_surface=TTF_RenderText_Solid(font,"Hello World!", color))) {
//handle error here, perhaps print TTF_GetError at least
printf("Error: %s\n", TTF_GetError());
}
/* Initialize the Keyboard Event */
typedef struct{
Uint8 type;
Uint8 state;
SDL_keysym sym;
} SDL_KeyboardEvent;
typedef struct{
Uint8 scancode;
SDLKey sym;
SDLMod mod;
Uint16 unicode;
} SDL_keysym;
/* Enter main game loop */
printf("Press [ESCAPE] to quit!\n");
while(!quit){
/* Wait for an event */
if(SDL_WaitEvent(&event)){
HandleKeyboardEvent(&event);
}
}
gameloop();
/* Shutdown code goes here */
return 1;
}
Code:
/* game.c - Main game loop */
#include <stdio.h>
#include "game.h"
char game_state = INIT;
void gameloop(void) {
switch(game_state) {
case INIT:
/* Game initialization code goes here */
break;
case INTRO:
/* Game intro sequence code goes here */
break;
case MENU:
/* Game menu goes here */
break;
case GAME:
/* Main game code goes here */
break;
case SHUTDOWN:
/* Game shutdown code goes here */
break;
default:
fprintf(stderr, "Bad game state");
break;
}
}
Code:
/* game.h - Game loop definitions and prototypes */
#include <SDL.h>
#include <SDL_ttf.h>
#ifndef __GAME_H__
#define __GAME_H__
#define INIT 0
#define INTRO 1
#define MENU 2
#define GAME 3
#define SHUTDOWN 4
#endif
I keep getting the error: incompatible type for argument 3 of 'TTF_RenderText_Solid'