-6

I've created a window, but the image don't render on it

I have tried a lot of things, but none worked.

Here is part of the program

janela1 = SDL_CreateWindow("Arkanoid", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, janx, jany, SDL_WINDOW_SHOWN);
rend = SDL_CreateRenderer(janela1, -1, SDL_RENDERER_ACCELERATED);
rwop = SDL_RWFromFile("bola.png", "rb");
textura = IMG_LoadTexture_RW(rend, rwop, NULL);
if (textura == nullptr || rwop == nullptr){
    cout << "erro";
}
SDL_Rect textura_retangulo;
textura_retangulo.h = 100;
textura_retangulo.w = 100;
textura_retangulo.x = 100;
textura_retangulo.y = 100;
SDL_RenderClear(rend);
SDL_RenderCopy(rend, textura, NULL, &textura_retangulo);
SDL_RenderPresent(rend);

I think the problem was in the RenderCopy, I don't know if is needed to do something else to render the image, because in the way is now nothing happen

1
  • Are you getting any error messages? Do all of the SDL functions return without error values?
    – Jonny D
    Apr 20, 2015 at 15:49

1 Answer 1

0

First of, you should declare the int values of janx and jany before declaring the window.

#include <SDL.h>
#include <SDL_image.h>
#include <iostream>
#include <conio> 

int janx = 100; //change both of these into your preferred number
int jany = 100;

SDL_Window *janela1 = SDL_CreateWindow("Arkanoid", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, janx, jany, SDL_WINDOW_SHOWN);
SDL_Renderer* rend = SDL_CreateRenderer(janela1, -1, SDL_RENDERER_ACCELERATED);
SDL_Texture *textura = IMG_LoadTexture_RW(rend, rwop, NULL);
SDL_RWops *rwop = SDL_RWFromFile("bola.png", "rb");
SDL_Event()* mainEvent = new SDL_Event();

if (textura == nullptr || rwop == nullptr){
    cout << "erro";
}
SDL_Rect textura_retangulo;
textura_retangulo.h = 100;
textura_retangulo.w = 100;
textura_retangulo.x = 100;
textura_retangulo.y = 100;


//I highly recommend you turn these into a loop, you'll find trouble once this expands.
void loop()
{
    while(mainEvent->type != SDL_QUIT)
    {
         SDL_PollEvent(mainEvent);
         SDL_RenderClear(rend);
         SDL_RenderCopy(rend, textura, NULL, &textura_retangulo);
         SDL_RenderPresent(rend);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.