Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problems when rendering string  (Read 4283 times)

0 Members and 1 Guest are viewing this topic.

jdw

  • Newbie
  • *
  • Posts: 3
    • View Profile
Problems when rendering string
« on: August 09, 2011, 07:59:36 pm »
Code: [Select]

#include <SFML/Audio.h>
#include <SFML/Graphics.h>
#include <stdio.h>
#include <SFML/Graphics/Font.h>

sfFont* g_debugFont = 0;
static sfWindowSettings WINDOW_SETTINGS = {24, 8, 0};
static sfVideoMode VIDEO_MODE = {800, 600, 32};
static sfRenderWindow* APP;

typedef enum {
        AOK,
        NO_DEBUG_FONT,
        FAILED_VIDEO_MODE,
        FAILED_LOADING_FONT_FILE
} F_EXIT;

static int
init() {
        // Loading debug font
        g_debugFont = sfFont_CreateFromFile("FreeMonoBold.ttf", 50, NULL);
        if (!g_debugFont) return FAILED_LOADING_FONT_FILE;

        return AOK;
}

int
main() {
        sfImage* t_pImage;
        sfString* t_pText = 0;
        sfSprite* t_pSprite = 0;

        int t_initReturn;
        if ((t_initReturn = init())) {
                printf("init() failed with code: %d\n", t_initReturn);
                return t_initReturn;
        }

        sfEvent t_event;
        int t_quit = 0;

        int t_modeCount = sfVideoMode_GetModesCount();
        printf("Graphics mode count: %d\n", t_modeCount);
        for (int i = 0; i < t_modeCount; ++i) {
                sfVideoMode t_mode = sfVideoMode_GetMode(i);
                printf("%dx%d, %dbpp\n", t_mode.Width, t_mode.Height, t_mode.BitsPerPixel);
        }

        // Create the main window
        APP = sfRenderWindow_Create(VIDEO_MODE, "SWPS", sfResize | sfClose, WINDOW_SETTINGS);
        if (!APP) return EXIT_FAILURE;

        // Load a sprite to display
        t_pImage = sfImage_CreateFromFile("ass/cute_image.jpg");
        if (!t_pImage) return EXIT_FAILURE;
        t_pSprite = sfSprite_Create();
        sfSprite_SetImage(t_pSprite, t_pImage);

        // Create a graphical string to display
        t_pText = sfString_Create();
        sfString_SetFont(t_pText, g_debugFont);
        sfString_SetText(t_pText, "Hello");
        sfString_SetSize(t_pText, 50);
        sfColor t_color = {200,200,200,5};

        // Start the game loop
        while (sfRenderWindow_IsOpened(APP)) {
                // Process events
                while (sfRenderWindow_GetEvent(APP, &t_event)) {
                        if (t_event.Type == sfEvtKeyPressed) {
                                if (t_event.Key.Code == sfKeyEscape) {
                                        t_quit = 1;
                                }
                        }

                        // Close window : exit
                        if (t_event.Type == sfEvtClosed || t_quit)
                 sfRenderWindow_Close(APP);
         }

                // Clear the screen
                sfRenderWindow_Clear(APP, sfBlack);
                // Draw the sprite
                sfRenderWindow_DrawSprite(APP, t_pSprite);
                // Draw the string
                sfRenderWindow_DrawString(APP, t_pText);
                // Update the window
                sfRenderWindow_Display(APP);
     }

        // Cleanup resources
        sfString_Destroy(t_pText);
        sfRenderWindow_Destroy(APP);

        return EXIT_SUCCESS;
 }


... yields...

http://dl.dropbox.com/u/4763175/2011-08-09%2019.54.29.jpg

Which is (offcourse) not what I want, I'd like the string to render "Hello" as in the code (and is now rendered as the transparent rectangles instead) and I have no idea as to why the whole font map is rendered...

... on KUbuntu 11.04, CSFML-1.6 - thanks for all help!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problems when rendering string
« Reply #1 on: August 09, 2011, 08:15:41 pm »
Can you describe what you expect and what happens, or do we have to decode your source code? ;)

And could you remove all the commented lines? It's confusing without syntax highlighting.
Laurent Gomila - SFML developer

jdw

  • Newbie
  • *
  • Posts: 3
    • View Profile
Problems when rendering string
« Reply #2 on: August 09, 2011, 09:12:09 pm »
Original post updated - also, when compiling the example found in the main page of the CSFML documentation, everything renders just fine.

jdw

  • Newbie
  • *
  • Posts: 3
    • View Profile
Problems when rendering string
« Reply #3 on: August 10, 2011, 11:10:02 pm »
Bump?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problems when rendering string
« Reply #4 on: August 11, 2011, 07:55:26 am »
I have no idea, sorry.

Could you simplify your code to have something minimal that reproduces only the problem?
Laurent Gomila - SFML developer

 

anything