simple button

hi i m trying to create a simple button but i get the following error.

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
.............
.............
Font * font = sysMain.OpenFont("calibri.ttf", 10);

    Color groundC = {80, 80, 80}, ground_onC = {220, 220, 220}, ground_clickC = {50, 50, 50}, textC = {255, 255, 255};

    Texture * tex2 = texMain.CreateRGBTexture(ren, 250, 250, 32, {0, 0, 0});

    fge::button myBtn;
    Rect myBtnRect;
    myBtnRect.h = 130;
    myBtnRect.w = 25;
    myBtnRect.x = 100;
    myBtnRect.y = 100;
    btnMain.CreateButton(myBtn, "test", ren, font, &myBtnRect, groundC, ground_onC, ground_clickC, textC);
.............
.............


buttonFuncs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void buttonFuncs::CreateButton(button &btn, std::string btnTitle, Renderer * renderer, Font * font, Rect * rect,
                                 Color groundC, Color ground_onC, Color ground_clickC, Color textC)
  {
    texture txtr;
    text txt;

    btn.ground = txtr.CreateRGBTexture(renderer, rect->w, rect->h, 32, groundC);

    btn.ground_on = txtr.CreateRGBTexture(renderer, rect->w, rect->h, 32, ground_onC);

    btn.ground_click = txtr.CreateRGBTexture(renderer, rect->w, rect->h, 32, ground_clickC);

    textSprite * txtSprt = txt.CreateTextSprite(btnTitle, renderer, font, textC);
    btn.text = txtSprt->texture;

    btn.grndRect.w = rect->w;
    btn.grndRect.h = rect->h;
    btn.grndRect.x = rect->x;
    btn.grndRect.y = rect->y;

    btn.txtRect.x = (btn.grndRect.w - txtSprt->rect.w) / 2;
    btn.txtRect.y = (btn.grndRect.h - txtSprt->rect.h) / 2;
  }


it compiles fine but debugger says
Debugging starts
HEAP[test2.exe]: 
Heap block at 00329308 modified at 00329321 past requested size of 11


thx everyone in advance any further info needed will be provided
Last edited on
i guess i found the source of this problem

1
2
3
4
5
6
7
8
9
10
11
  Surface * surface::CreateRGBSurface(int width, int height, int depth, Uint32 R, Uint32 G, Uint32 B, Uint32 A)
  {
    Surface *tmp;
    
    tmp = SDL_CreateRGBSurface(0, width, height, depth, R, G, B, A);

    if(!tmp)
        Logger("at function \"surface::CreateRGBSurface\" failed to create surface");

    return tmp;
  }


it seems like i just dont know how to handle SDL_BIG_ENDIAN. or maybe i m just talking nonsense???

EDIT: also after testing this
1
2
3
4
5
6
    if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
      std::cout << "yes" << std::endl;
    else if(SDL_BYTEORDER == SDL_LIL_ENDIAN)
      std::cout << "no" << std::endl;
    else
      std::cout << "shit" << std::endl;


the output was
no
Last edited on
when i tried even this fails although it is the example given in the wiki of SDL2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
#else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
#endif

Surface * surf3 = SDL_CreateRGBSurface(0, 150, 150, 32,
                                           rmask, gmask, bmask, amask);
Texture * tex3 = texMain.CreateTextureFromSurface(ren, surf3);
SDL_FreeSurface(surf3);

renMain.RenderClear(ren);
renMain.RenderCopy(ren, tex3, NULL, NULL);
renMain.RenderPresent(ren);


it ends up with a black window not showing anything
ok i solved the problem like this although it wastes resources

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
Surface * surface::CreateRGBSurface(int width, int height, int depth, Color color)
  {
    Surface *tmp;

    tmp = SDL_CreateRGBSurface(0, width, height, depth, 0, 0, 0, 0);

    Uint32 final;

    if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
      {
        final = static_cast<Uint32>(color.r)*static_cast<Uint32>(std::pow(16, 6)) +
            static_cast<Uint32>(color.g)*static_cast<Uint32>(std::pow(16, 4)) +
            static_cast<Uint32>(color.b)*static_cast<Uint32>(std::pow(16, 2)) +
            static_cast<Uint32>(color.a);
      }
    else
      {
        final = static_cast<Uint32>(color.a)*static_cast<Uint32>(std::pow(16, 6)) +
            static_cast<Uint32>(color.r)*static_cast<Uint32>(std::pow(16, 4)) +
            static_cast<Uint32>(color.g)*static_cast<Uint32>(std::pow(16, 2)) +
            static_cast<Uint32>(color.b);
      }

    SDL_FillRect(tmp, NULL, final);

    if(!tmp)
      Logger("at function \"surface::CreateRGBSurface\" failed to create surface");

    return tmp;
  }


EDIT: this is the fixed one
Last edited on
Topic archived. No new replies allowed.