Sign in to follow this  

Applying one surface to another (SDL)

This topic is 3719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What am I missing here? Given this code:

void showWindow(SDL_Surface *screen)
    {
        temp = loadImage("window.png");
        font = TTF_OpenFont("Explosive.ttf", 20);
        temp2 = TTF_RenderText_Solid(font, "Summon", textColor);

        SDL_Color textColor = {200, 0, 100};
        apply_surface(window.x, window.y, temp, screen, NULL);
        apply_surface(10, 25, temp2, temp, NULL);

        SDL_FreeSurface(temp);
        SDL_FreeSurface(temp2);

        TTF_CloseFont(font);
    }

Why can't I get the text to show up on top of the window? I've been looking at tutorials for awhile and haven't found anything that relates to this directly, though I'm probably just dumb and missing something obvious.

Share this post


Link to post
Share on other sites
Your calls to apply_surface are in the wrong order. The way you're doing it, first temp gets drawn onto screen, then temp2 gets drawn onto temp. temp2 will not be drawn on screen because at the time temp is applied to screen, temp2 has not been applied to it. So try switching the order of the apply_surface calls.

Share this post


Link to post
Share on other sites
Does this mean that you're loading window.png every time the screen is redrawn? That's a bad idea, because disk access is slow. Load the image once, use it as long as it needs to be used, and only then remove it. The same goes for fonts.

Share this post


Link to post
Share on other sites
Na I just wrote up that code quickly to be all inclusive (so you guys could see if I was leaving something out).

I actually got it working another way (but will probably go back and mess around with it some more now) where I just draw the text to screen after everything else but I wrote up a helper function to always apply the text in relation to the window (so it appears to be part of the window surface itself). It works, but its making more work for me now that I'm trying to recognize mouse clicks on the surface.

Share this post


Link to post
Share on other sites

This topic is 3719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this