Jump to content
  • Advertisement
Sign in to follow this  
deEnumerator

K i give up SDL question

This topic is 4677 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm getting this error when compiling: .\Graphics.cpp(32) : error C2664: 'SDL_UpperBlit' : cannot convert parameter 2 from 'SDL_Rect **' to 'SDL_Rect *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast It has to do with BlitSurface function(which is a #define for UpperBlit(i guess)).One of the Rect's i plan on using is at the top. Graphics.cpp
	mPaddleRect;
		mPaddleRect.x = 0;
		mPaddleRect.y = 0;
		mPaddleRect.w = 100;
		mPaddleRect.h = 16;
	mpPadRect = &mPaddleRect;
		

}

void CGraphics::Draw(SDL_Surface* screen, SDL_Surface* bitmap, SDL_Rect *pMySourceRect,
				int destX, int destY)
{
   // Part of the screen we want to draw the sprite to
   SDL_Rect dest;
   dest.x = destX;
   dest.y = destY;
   dest.w = pMySourceRect->w;
   dest.h = pMySourceRect->h;

   SDL_BlitSurface(bitmap, &pMySourceRect, screen, &dest);
}

Share this post


Link to post
Share on other sites
Advertisement
pMySourceRect is already a pointer. You don't need to have an & in front of it when you pass it to SDL_BlitSurface().

Share this post


Link to post
Share on other sites
Oh man, that just sent my C++ universe off its axis. [totally] Thanks

One other thing if you come back in here: if there is a page for it, do you know of a good reference that you personal use as far as naming conventions?

Share this post


Link to post
Share on other sites
Quote:
Original post by deEnumerator
Oh man, that just sent my C++ universe off its axis. [totally]


I think the problem is not from that but just a misunderstanding of how SDL_BlitSurface works. The function is declared as: int SDL_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); You have down the SDL_Surface*'s I'll assume, so for the SDL_Rects, they take in a pointer to some rectagle. The reason a pointer to a SDL_Rect has to be sent in is because if the specified rectangle lies outside of the screen, SDL will update that rect with the portion that was drawn, to which afterwards, you can check to see if the original rect you sent in was the same that was blitted.

So when you have something like this:
SDL_Rect src, dest; You know those are not pointers, so to get them to work with that function, you have to pass the address of those variables into the function, &src, &dest.

If you had something like this:
SDL_Rect *src = new SDL_Rect; SDL_Rect *dest = new SDL_Rect; You know you have pointers, so to get them to work with that function, you just have to pass in src, dest.

I think the problem was that in all of the tutorials/references to SDL out on the net, they always use &var when passing to that function, so you instinctively did the same thing. Well that's if I'm wrong about all of this. Either way, now you know. Here's a reference on pointers in C++ if you need to refresh your memory.

Share this post


Link to post
Share on other sites
Yeah, it was a tutorial i was refering to when i originally made that function, thats what it was in part, the other part being new to pointers and the & operator in general. Thanks for the input as usual. [wink]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!