Sign in to follow this  
willthiswork89

man filesplitting! help me out

Recommended Posts

willthiswork89    100
okay in my last post they helped me out and this is what i got
//main.cpp

#include "SDLENGINE.h"
#include <SDL/SDL.h>
using namespace std;

SDL_Surface* screen;
SDL_Surface* background;
int main(int argc,char* args[])
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
printf("Unable to INIT SDL");
return 1;
}


screen = SDL_SetVideoMode(SWIDTH,SHEIGHT,BPP,SDL_SWSURFACE);

if(screen == NULL)
{
printf("Unable to set Video Mode!");
return 1;
}

SDL_WM_SetCaption("TESTING SPLIT!",NULL);

background = Load_Image("background.bmp");

if(background == NULL)
{
printf("background turned out null!");
return 1;
}
Apply_Surface(0,0,&background,&screen);

if(SDL_Flip(screen) == -1)
{
printf("Unable to FLIP Screen");
return 1;
}

SDL_Delay(2000);

SDL_FreeSurface(background);

SDL_Quit();
}

//SDLENGINE.h
#ifndef SDLENGINE_H
#define SDLENGINE_H

#define SWIDTH 640
#define SHEIGHT 480
#define BPP 32

#include <SDL/SDL.h>
#include <string>
SDL_Surface* Load_Image(std::string filename);
void Apply_Surface(int x, int y,SDL_Surface *source, SDL_Surface *destination);

#endif

//SDLENGINE.cpp
#include "SDLENGINE.h"
#include <SDL/SDL.h>
#include <string>

using namespace std;

SDL_Surface* Load_Image(string filename)
{
SDL_Surface *temp = NULL;
SDL_Surface *final = NULL;

temp = SDL_LoadBMP(filename.c_str());

if(temp != NULL)
{
final = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
}
return final;
)


void Apply_Surface(int x,int y, SDL_Surface* const source, SDL_Surface* const destination)
{
     SDL_Rect Offset;
     
     Offset.x = x;
     Offset.y = y;
     
     SDL_BlitSurface(source,NULL,destination,&Offset);
}

im getting the error in main that... 1 C:\Documents and Settings\Kevin Stowe\Desktop\SDLShit\Project\main.cpp [Warning] `nul.gcda' is not a gcov data file for the SDLENGINE.h and 33 C:\Documents and Settings\Kevin Stowe\Desktop\SDLShit\Project\main.cpp cannot convert `SDL_Surface**' to `SDL_Surface*' for argument `3' to `void Apply_Surface(int, int, SDL_Surface*, SDL_Surface*)' for the applysurface...can someone tell me why?

Share this post


Link to post
Share on other sites
nullsquared    126
May I ask why you are passing an adress of a pointer (if that makes sense)? A pointer is an adress, you aren't passing a non-pointer to be using the '&' infront of it.


Apply_Surface(..., ..., src, dest);

// not
Apply_Surface(..., ..., &src, &dest);

//src and dest are already pointers!



Good luck!

(Nice folder name... SDLS#@t!)

Share this post


Link to post
Share on other sites
Drew_Benton    1861
Quote:
Original post by pulpfist
Someone told me that SDL_Surface is already defined as a pointer type


A SDL_Surface is defined as a non-pointer struct. When you use them though, you will use a pointer to a SDL_Surface due to the C-styled nature of SDL. When you pass them, once again due to how SDL is C-styled, you pass a SDL_Surface*. You could use a normal SDL_Surface if you really wanted to, but that's a bit too much work and error tracking. It'd be much better to wrap up the SDL API into C++ wrappers than try to use references and non-pointer SDL_Surface's.

Share this post


Link to post
Share on other sites
nullsquared    126
Quote:
Original post by willthiswork89
yes BUT when you pass a pointer to another cpp file..it gets taken as a COPY instead of directly editing the mempory of the pointer...thanks about the folder haha...i couldnt think of a good name lol


??? Really? How come I never knew that? Aww well. Anyways, try it the way I suggested, and tell me if it even works. Then once we solve the prob. we can change it back.

@pulpfist:
Noo... not really. It needs to be a pointer, but isn't already.

I guess you can do something like:

typedef (SDL_Surface*) pSDL_Surface;


DONT QUOTE ME ON THIS! I have *not* used typedefs for a *while*.

Share this post


Link to post
Share on other sites
Drew_Benton    1861
Quote:
Original post by willthiswork89
yes BUT when you pass a pointer to another cpp file..it gets taken as a COPY instead of directly editing the mempory of the pointer...


Nope, the way C/C++ work with pointers, you are passing the actual memory address of a particular object. When you perform operations on the dereferenced object, those changes are permanent, unlike when you pass a non-referenced parameter to a function.

Quote:
okay it compiled and i get an error that my background is turning out null. which has somting to do with my function Load_Image and returning final back to the background...


Your code looks good, so check to make sure that the file exists and is in the correct diretory in respect to where you are running the program.

Share this post


Link to post
Share on other sites
nullsquared    126
Quote:
Original post by Drew_Benton
Quote:
Original post by willthiswork89
yes BUT when you pass a pointer to another cpp file..it gets taken as a COPY instead of directly editing the mempory of the pointer...


Nope, the way C/C++ work with pointers, you are passing the actual memory address of a particular object. When you perform operations on the dereferenced object, those changes are permanent, unlike when you pass a non-referenced parameter to a function.

Quote:
okay it compiled and i get an error that my background is turning out null. which has somting to do with my function Load_Image and returning final back to the background...


Your code looks good, so check to make sure that the file exists and is in the correct diretory in respect to where you are running the program.


Yup, agreed. I knew you aren't getting a copy by supplying a pointer, but never really knew what I knew was known to be true ;)!

Share this post


Link to post
Share on other sites
Drew_Benton    1861
Quote:
Original post by willthiswork89
okay it compiled and i get an error that my background is turning out null. which has somting to do with my function Load_Image and returning final back to the background...


So it's failing on the segment:

if(background == NULL)
{
printf("background turned out null!");
return 1;
}

Correct? I mean it says "background turned out null!" right? If so, then see if you can further track down the problem.


SDL_Surface* Load_Image(string filename)
{
SDL_Surface *temp = NULL;
SDL_Surface *final = NULL;

temp = SDL_LoadBMP(filename.c_str());

if(temp != NULL)
{
final = SDL_DisplayFormat(temp);
if( final == NULL )
{
printf("Error, DisplayFormat failed!");
}
SDL_FreeSurface(temp);
}
else
{
printf("Error, image could not be loaded via SDL_LoadBMP");
}
return final;
)





Tell us what error you get, or well what message is now displayed.



And here's my other post, that I posted, but lost my net connection so it did not go though.

Quote:
Original post by pulpfist
Quote:

yes BUT when you pass a pointer to another cpp file..it gets taken as a COPY instead of directly editing the mempory of the pointer...


One of the other recent thrads talk about this item too...

It doesnt matter if it is in another cpp file realy, it always send a copy


I will first kindly refer you to a few tutorials on Pointers in C++:
Link 1
Link 2

Now let me re-explain this concept with a quick trivial example.


void SetVal(int var)
{
var = 0;
}

void SetPtrVal(int* var)
{
*var = 0;
}

void Function1()
{
int x = 42;
SetVal(x);
// Will display 42
cout << x;

int y = 1024;
SetVal2(&y);
// Will display 0
cout << y;
}





In relation to your other post:

// This sends a 'copy' of the object to the function, which is not modifiable
// in terms of the ORIGINAL object is not modified, unless a few other specific things happen
int render(Surface srf)

// This sends the address of the object you are passing in.
// It IS the real object when it is dereferenced and represents the address of the real object as a pointer
int render(Surface* srf)

// This sends the address of the pointer that is pointing to the object you are passing in. Or something weird like that, it depends on how you are using it, what you pass in.
int render(Surface* &srf)




Just trying to clear that up for you [wink]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this