SDL_BlitSurface won't work

1
2
3
4
skin=IMG_Load("./assets/Windowskins/WindskinA.png");
SDL_BlitSurface( skin, NULL, output_window, NULL );
t = SDL_CreateTextureFromSurface(Surf_Display,output_window);
CSurface::OnDraw(Surf_Display, t, x, y,0,0,150,50);



it returns no error, but don't show the image.
Last edited on
it returns no error

Have you checked? IMG_Load returns a null pointer if it fails to load the image. You can use IMG_GetError() to get the error message.

1
2
3
4
5
skin=IMG_Load("./assets/Windowskins/WindskinA.png");
if (!skin)
{
	std::cout << "IMG_Load: " << IMG_GetError() << std::endl;
}
Last edited on
it is loading,
if i change the code to:

1
2
3
4
5
skin=IMG_Load("./assets/Windowskins/WindskinA.png");
SDL_BlitSurface( skin, NULL, output_window, NULL );
t = SDL_CreateTextureFromSurface(Surf_Display,skin);
CSurface::OnDraw(Surf_Display, t, x, y,0,0,150,50);

it work
but the BlitSurface is not working
Last edited on
Is the output_window big enough, correct format?
this is the code:
for CChat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//=============================================================================
#include "CChat.h"
#include "CApp.h"
//=============================================================================
CChat::CChat() {
}

//=============================================================================
int CChat::OnLoad(int x,int y, int h, int w,SDL_Renderer* Surf_Display)
{
skin=IMG_Load("./assets/Windowskins/WindskinA.png");





SDL_BlitSurface( skin, NULL, output_window, NULL );

t = SDL_CreateTextureFromSurface(Surf_Display,output_window);
CSurface::OnDraw(Surf_Display, t, x, y,0,0,150,50);

}



and for CChat.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//=============================================================================
//=============================================================================
#ifndef _CChat_H_
#define _CChat_H_

#include "CChat.h"
#include <vector>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <iostream>
#include <sstream>
#include <cstring>
//=============================================================================
class CChat  {
    public:
SDL_Rect* clip;
SDL_Rect offset;
SDL_Surface* output_window;
SDL_Surface* skin;

SDL_Texture *t;
SDL_Color textcolor;
TTF_Font *font;
SDL_Surface *message;
int r,g,b;
const char* text;
const char* file;
int x,y;
int size;
SDL_Renderer* Surf_Display;
    CChat();

    int OnLoad(int x,int y, int h, int w,SDL_Renderer* Surf_Display);

  
};

//=============================================================================

#endif
Looks like output_window is never initialized.
what i should do? i don't know how to do it.
I don't understand the purpose of SDL_BlitSurface and output_window in your program. Do you need them?
i will create a single chat window with pieces of images, to create borders.
i really need it, because i will use the same image in another class, and the size of the window depends the parameter used to load it.
using BlitSurface i will able to move the window.
if don't use BlitSurface, and will have a lot of pieces of a window on the screen instead of a window
Last edited on
Maybe you want to use SDL_CreateRGBSurface to create the surface that output_window should point to.

https://wiki.libsdl.org/SDL_CreateRGBSurface
It's working now, thanks.
Last edited on
Topic archived. No new replies allowed.