[DerelictSDL] SDL_RenderCopy does not accept optional arguements when written in a file aside from main

Lucien via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 24 02:42:57 PST 2015


On Thursday, 24 December 2015 at 09:41:39 UTC, Jack wrote:
> So I have separated my texture rendering methods in another 
> file and have run into a problem hence the title name.
>
> #main.d
> ----------
>
> void render()
> {
> SDL_RenderClear(renderTarget);
> renderSprite(renderTarget);
> SDL_RenderPresent(renderTarget);
> }
> ----------
> #other_file.d
> -----------
> void renderSprite(SDL_Renderer _renderTarget)
> {
>
> SDL_Texture texture = 
> SDL_CreateTextureFromSurface(_renderTarget, 
> IMG_Load("image.png"));
>
> SDL_RenderCopy(_renderTarget,texture, null,null);
> }
> ----------
>
> Error: cannot implicitly convert expression (null) of type 
> typeof(null) to SDL_Rect
> Error: cannot implicitly convert expression (null) of type 
> typeof(null) to SDL_Rect
>
> =====================
> But when I do this:
>
> #main.d
> -------------------
>
> void render()
> {
> SDL_RenderClear(renderTarget);
> SDL_RenderCopy(renderTarget,texture,null,null);
> SDL_RenderPresent(renderTarget);
> }
> --------------------
>
> It works with no problem. I've DerelictSDL2.load and SDL_Init 
> already.
> So is this a bug or am I doing something wrong here?

You need a pointer to renderTarget.


#other_file.d

---------------------
module my.sdl.project;

import derelict.sdl2.sdl;
import derelict.sdl2.image;


void renderSprite(SDL_Renderer* _renderTarget)
{
     SDL_Texture* texture = 
SDL_CreateTextureFromSurface(_renderTarget, 
IMG_Load("image.png"));
     SDL_RenderCopy(_renderTarget,texture, null,null);
}
---------------

#main.d
-----------

import my.sdl.project;
//...
-----------


More information about the Digitalmars-d-learn mailing list