nothing shown

i was trying to make bg.bmp to shown and it simply works fine but nothing shown

MC_FuncsB_GLoop.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef MC_FUNCSB_GLOOP_H
#define MC_FUNCSB_GLOOP_H

#include <SDL/SDL.h>
#include <string>

class MC_FuncsB_GLoop
{
    public:
        MC_FuncsB_GLoop();
        virtual ~MC_FuncsB_GLoop();
        static bool Init();
        static bool Blit();
        static bool Load(SDL_Surface* Name, std::string Path);
    protected:
    private:
};

#endif // MC_FUNCSB_GLOOP_H 


MC_FuncsB_GLoop.cpp
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
42
43
44
45
46
#include "../include/MC_FuncsB_GLoop.h"

SDL_Surface* bg;
SDL_Surface* Display = NULL;

MC_FuncsB_GLoop::MC_FuncsB_GLoop()
{

}

MC_FuncsB_GLoop::~MC_FuncsB_GLoop()
{
    //dtor
}

bool MC_FuncsB_GLoop::Init(){
    //--------------------------
    int MCWidth     = 640;
    int MCHeight    = 480;
    int MCBpp       = 32;
    //--------------------------
    if(SDL_Init(SDL_INIT_EVERYTHING) < 0){return false;}

    Display = SDL_SetVideoMode(MCWidth, MCHeight, MCBpp, SDL_HWSURFACE|SDL_DOUBLEBUF);

    if(
       Display                 == NULL ||
       Load(bg, "gfx\\bg.bmp") == false
    )return false;
    else return true;
}

bool MC_FuncsB_GLoop::Load(SDL_Surface* Name, std::string Path){
    Name = NULL;
    Name = SDL_LoadBMP(Path.c_str());
    if(Name == NULL){return false;}
    else{return true;}
}

bool MC_FuncsB_GLoop::Blit(){
    SDL_Rect Rect;
    SDL_Rect Rect2;
    SDL_BlitSurface(bg, &Rect, Display, &Rect2);
    SDL_Flip(Display);
    return true;
}


MCMain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif

#include <SDL/SDL.h>
#include "include/MC_FuncsB_GLoop.h"
#include "include/MC_GLoop.h"
#include "include/MC_FuncsA_GLoop.h"

int main ( int argc, char** argv )
{
    if(MC_FuncsB_GLoop::Init() == false)return 1;
    if(MC_FuncsB_GLoop::Blit() == false)return 2;
    SDL_Delay(2000);

    return 0;
}


and the compiler error
1
2
3
Checking for existence: C:\Users\Ceset\Desktop\MC\Mini Commandos\bin\Debug\Mini Commandos.exe
Executing: "C:\Users\Ceset\Desktop\MC\Mini Commandos\bin\Debug\Mini Commandos.exe"  (in C:\Users\Ceset\Desktop\MC\Mini Commandos\.)
Process terminated with status 0 (0 minutes, 2 seconds)


shows nothing but a black screen
Last edited on
closed account (N36fSL3A)
You don't have compiler errors.

shows nothing but a black screen
Does the window open or is your whole screen black?

By the way, you aren't looping anything.

Where the hell is your load function anyway?
Remove static from the functions in MC_FuncsB_GLoop and put bg inside the class.

Your actual problem is Load(SDL_Surface* Name
You can change Name itself but not the pointer

why don't you do it like so:
SDL_Surface* Load(std::string Path);
when it returns NULL it didn't work.
well Lumpkin a windows opens but a black window shows up. not all my screen. sorry for the misunderstanding

coder777 when i removed the static it gives me cannot call member function without object error.
and when i put bg anywhere else from there. it gives me multiple definiton error. and funnily i dont know how to define it inside class{}; in the header file.

and the third thing u said made me freak out. how can i make bg pass trough the function if i dont have Name?? a further explaination and some example would be nice thx in advance
EDIT: i have did some tests problem does seem like it is load func like coder777 said. couse display do shown on the window

EDIT2: i change blit to
1
2
3
4
5
bg = SDL_LoadBMP("gfx\\bg.bmp");
    SDL_FillRect(Display, 0, SDL_MapRGB(Display->format, 255, 255, 255));
    SDL_BlitSurface(bg, 0, Display, 0);
    SDL_Flip(Display);
    return true;

and it worked fine
so the prob is truely load function. it doesnt loads bg.bmp but dont know why
Last edited on
first of all i realized a few things. my load function is totally idiotic. dont know what was i thinking. secondly i dont know what would i do if someone were to ask me to help something this idiotic.

so thx everyone for patience. especially both of u

i just removed my load function thats all
so the prob is truely load function. it doesnt loads bg.bmp but dont know why
It does load the bitmap, but it discards it when it exits.

It's very slow to load the bitmap everytime you show it.
Also: MC_FuncsB_GLoop is neither a real class nor a valid name.

I could provide something that gives you an idea how it could be done if you're interested...
@coder777 yeah i m interested. even though i fixed my prob. learning is no harm right
Last edited on
Well, think obect oriented.
What kind of object do you want?
Answer: image
What should this image do:
Answer: load and blit
So lets make this class:
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
class CImage
{
    public:
        CImage();
        virtual ~CImage();
        void Blit(); // Since Blit cannot fail -> void
        bool Load(std::string Path);
    protected:
    private:
SDL_Surface* bg; // Member variable
};

extern SDL_Surface* Display; // Note: extern. This is a global resource defined somewhere else

CImage::CImage() : bg(NULL) // Important! Uninitialized variable is very bad
{
}

CImage::~CImage()
{
  // Free bg
}


bool CImage::Load(std::string Path){
  bg = SDL_LoadBMP(Path.c_str());
  return (bg != NULL);
}

void CImage::Blit(){
    SDL_FillRect(Display, 0, SDL_MapRGB(Display->format, 255, 255, 255));
    SDL_BlitSurface(bg, 0, Display, 0);
    SDL_Flip(Display);
}
How to use the class:
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
#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif

#include <SDL/SDL.h>
#include "include/image.h" // Note!
#include "include/MC_GLoop.h"
#include "include/MC_FuncsA_GLoop.h"

SDL_Surface* Display = NULL; // This is the gobal Display (kind of constant)
// it is used by image. Other than that image has nothing to do with it


int main ( int argc, char** argv )
{
// The following are once in a lifetime of the program. So it makes sense to put them at the very beginning of the program.
    //--------------------------
    int MCWidth     = 640;
    int MCHeight    = 480;
    int MCBpp       = 32;
    //--------------------------
    if(SDL_Init(SDL_INIT_EVERYTHING) < 0){return 1;}

    Display = SDL_SetVideoMode(MCWidth, MCHeight, MCBpp, SDL_HWSURFACE|SDL_DOUBLEBUF);

// Now we want the image

    CImage image;

    if(image.Load("gfx\\bg.bmp") == false)return 1;
    image.Blit();
    SDL_Delay(2000);

    return 0;
}
Topic archived. No new replies allowed.