Jump to content
  • Advertisement
Sign in to follow this  
willthiswork89

man filesplitting! help me out

This topic is 4588 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

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
Advertisement
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
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 this post


Link to post
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 this post


Link to post
Share on other sites
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
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!