man filesplitting! help me out

Recommended Posts

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);

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>
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 *temp = NULL;
SDL_Surface *final = NULL;

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 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);// notApply_Surface(..., ..., &src, &dest);//src and dest are already pointers!

Good luck!

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

Share on other sites
pulpfist    528
Someone told me that SDL_Surface is already defined as a pointer type

Share on other sites
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

Share on other sites
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...

Share on other sites
Drew_Benton    1861
Quote:
 Original post by pulpfistSomeone 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 on other sites
pulpfist    528
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...

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

http://www.gamedev.net/community/forums/topic.asp?topic_id=360657

Share on other sites
nullsquared    126
Quote:
 Original post by willthiswork89yes 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 on other sites
Drew_Benton    1861
Quote:
 Original post by willthiswork89yes 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 on other sites
nullsquared    126
Quote:
Original post by Drew_Benton
Quote:
 Original post by willthiswork89yes 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 on other sites
i know for a fact its there, as ive had this problem once before so if anyof you want my code ill wrap it in a zip and put it up on a geocities site

Share on other sites
well any one? i really would love to get this working?

Share on other sites
Drew_Benton    1861
Quote:
 Original post by willthiswork89okay 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...

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++:

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 happenint 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 pointerint 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 on other sites
if you look at my code i have SDL_Surface *source??? i dont get it... should that be able to directly edit the crap in mains pointer then?

Share on other sites
pulpfist    528
I cant see that I said anything that conflicts with this, but you sure got the technicalities right. Thanks

Share on other sites
okay the error is with loading through LOAD_BMP so...what i need to do is use SDL_image.h and use that one and try it i suppose?

Share on other sites
okay i fixed it! thanks for the help guys it turned out that the LoadBMP was bad so i included sdl_image and did IMG_Load and it worked fine! im excited haha thanks guys for the help