Thread overview |
---|
December 24, 2015 [DerelictSDL] SDL_RenderCopy does not accept optional arguements when written in a file aside from main | ||||
---|---|---|---|---|
| ||||
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? |
December 24, 2015 Re: [DerelictSDL] SDL_RenderCopy does not accept optional arguements when written in a file aside from main | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack | 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; //... ----------- |
December 24, 2015 Re: [DerelictSDL] SDL_RenderCopy does not accept optional arguements when written in a file aside from main | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lucien | On Thursday, 24 December 2015 at 10:42:57 UTC, Lucien wrote:
> On Thursday, 24 December 2015 at 09:41:39 UTC, Jack wrote:
>> [...]
>
> 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;
> //...
> -----------
I actually have a pointer in the original project but I seem to forgot it when I'm typing this example. Sorry bout the misunderstanding, but yeah problem still stands.
|
December 24, 2015 Re: [DerelictSDL] SDL_RenderCopy does not accept optional arguements when written in a file aside from main | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack | On Thursday, 24 December 2015 at 11:32:24 UTC, Jack wrote:
> On Thursday, 24 December 2015 at 10:42:57 UTC, Lucien wrote:
>> On Thursday, 24 December 2015 at 09:41:39 UTC, Jack wrote:
>>> [...]
>>
>> 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;
>> //...
>> -----------
>
> I actually have a pointer in the original project but I seem to forgot it when I'm typing this example. Sorry bout the misunderstanding, but yeah problem still stands.
I can't help you without your original code.
|
December 24, 2015 Re: [DerelictSDL] SDL_RenderCopy does not accept optional arguements when written in a file aside from main | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lucien | On Thursday, 24 December 2015 at 12:42:11 UTC, Lucien wrote:
> On Thursday, 24 December 2015 at 11:32:24 UTC, Jack wrote:
>> On Thursday, 24 December 2015 at 10:42:57 UTC, Lucien wrote:
>>> [...]
>>
>> I actually have a pointer in the original project but I seem to forgot it when I'm typing this example. Sorry bout the misunderstanding, but yeah problem still stands.
>
> I can't help you without your original code.
I think I fixed it. I was initializing SDL_Rects to nulls inside some of the arguments. It was a slight case of Spaghetti Code.
Oh well, thank you for your time.
|
Copyright © 1999-2021 by the D Language Foundation