Jump to content
  • Advertisement
Sign in to follow this  
willthiswork89

code orginization

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

main.cpp:

#include "multiply.h"

int main()
{
int result = my_square(2);
...
return 0;
}




multiply.h:

int my_square(int value);




multiply.cpp:

#include "multiply.h"

int my_square(int value)
{
return value * value;
}




Thats the bottom line I think.
As said earlier you must add both main.cpp and multiply.cpp to your project.
Some IDE's will automatically add main.cpp for you, but I believe Dev-C++ will not.

Share this post


Link to post
Share on other sites
Advertisement
alright heres what i got from after reading your posts please tell me if i did somthing wrong or somthing needs to be added. it compiled fine though

//applyimage.h

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

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

SDL_Surface *load_image(string filename);

void apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination);



theres my applyimage.h defining my functions and defines.


//applyimage.cpp

#include <SDL/SDL.h>
#include <string>

using namespace std;


SDL_Surface *load_image(string filename)
{
SDL_Surface *loadedimage = NULL;
SDL_Surface *changedbpp = NULL;


loadedimage = SDL_LoadBMP(filename.c_str());


if(loadedimage != NULL)
{
changedbpp = SDL_DisplayFormat(loadedimage);

SDL_FreeSurface(loadedimage);
}
return changedbpp;
}

void apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination)
{
SDL_Rect ofs;

ofs.x = x;
ofs.y = y;

SDL_BlitSurface(source,NULL,destination,&ofs);
}





there is the actual definition of the applyimage.h


//main.cpp
#include "applyimage.h"
#include <SDL/SDL.h>



SDL_Surface *message = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;

int main(int argc, char* args[])
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}

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

if(screen == NULL)
{
return 1;
}

SDL_WM_SetCaption("Blitting Here!", NULL);

message = load_image("hello_world.bmp");
background = load_image("background.bmp");

apply_surface(0,0,background,screen);

apply_surface(180,140,message,screen);

if(SDL_Flip(screen) == -1)
{
return 1;
}

SDL_Delay(10000);

SDL_FreeSurface(message);
SDL_FreeSurface(background);

SDL_Quit();
}



i know main isnt made to handle events i know how to do that but for simplicity's sake i kept it as simple as i could...

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!