Weird Errors

I just added image.h and image.cpp to my project. Here's there source code:

[code]
iamge.h

#ifndef _IMAGE_H_
#define _IMAGE_H_

#include
#include
class image {
public:
SDL_Surface* loadBitmapRWops(char *resourcefilename, char *bitmapfilename);
void loadImage(char* filename);
void blitBitmap(SDL_Surface *dest, Uint16 x, Uint16 y);
image();
virtual ~image();

SDL_Surface* getImage();
private:
SDL_Surface* bitmap;
}
#endif
[/code]


[code]
image.cpp

I commented out one function because I was having troubles with it, and it's not important at the moment.

#include
#include

#include "image.h"
#include

SDL_Surface *loadBitmapRWops(char *resourcefilename, char *bitmapfilename)
{/*
//Get the bitmap's buffer and size from the resource file
int filesize = 0;
//char *buffer = GetBufferFromResource(resourcefilename, bitmapfilename, &filesize);

//Load the buffer into a surface using RWops
SDL_RWops *rw = SDL_RWFromMem(buffer, filesize);
SDL_Surface *temp = SDL_LoadBMP_RW(rw, 1);

//Release the bitmap buffer memory
free(buffer);

//Were we able to load the bitmap?
if (temp == NULL)
{
printf("Unable to load bitmap: %s
", SDL_GetError());
exit(1);
}

//Convert the image to optimal display format
SDL_Surface *image;
image = SDL_DisplayFormat(temp);

//Free the temporary surface
SDL_FreeSurface(temp);

//Return our loaded image
return image;*/
}

void image::loadImage(char* filename) {
SDL_Surface *temp;

temp =IMG_Load(filename);
if (temp == NULL) {
printf("Unable to load bitmap: %s
", SDL_GetError());
return NULL;
}

bitmap = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
return;
}

void image::blitBitmap(SDL_Surface *destSurf, Uint16 x, Uint16 y) {
SDL_Rect src, dest;

src.x = 0;
src.y = 0;
src.w = bitmap->w;
src.h = bitmap->h;

dest.x = x;
dest.y = y;
dest.w = destSurf->w;
dest.h = destSurf->h;

SDL_BlitSurface(bitmap, &src, destSurf, &dest);
}
image::~image() {
SDL_FreeSurface(bitmap);
}

image::image() {
return;
}

SDL_Surface* image::getImage() {
return bitmap;
}[/code]

Here's the code for main.cpp

[code]#include
#include

#include
#include

#include "SDLInit.h"
#include "image.h"

SDL_Surface* screen;

image mario;

void Slock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
if ( SDL_LockSurface(screen) < 0 )
{
return;
}
}
}

void Sulock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
SDL_UnlockSurface(screen);
}
}

void DrawPixel(SDL_Surface *screen, int x, int y,
Uint8 R, Uint8 G, Uint8 B)
{
Uint32 color = SDL_MapRGB(screen->format, R, G, B);
switch (screen->format->BytesPerPixel)
{
case 1: // Assuming 8-bpp
{
Uint8 *bufp;
bufp = (Uint8 *)screen->pixels + y*screen->pitch + x;
*bufp = color;
}
break;
case 2: // Probably 15-bpp or 16-bpp
{
Uint16 *bufp;
bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;
*bufp = color;
}
break;
case 3: // Slow 24-bpp mode, usually not used
{
Uint8 *bufp;
bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3;
if(SDL_BYTEORDER == SDL_LIL_ENDIAN)
{
bufp[0] = color;
bufp[1] = color >> 8;
bufp[2] = color >> 16;
} else {
bufp[2] = color;
bufp[1] = color >> 8;
bufp[0] = color >> 16;
}
}
break;
case 4: // Probably 32-bpp
{
Uint32 *bufp;
bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;
*bufp = color;
}
break;
}
}

void DrawScene(SDL_Surface *screen)
{
Slock(screen);
for(int x=0;x<640;x++)
{
for(int y=0;y<480;y++)
{
DrawPixel(screen, x,y,y/2,y/2,x/3);
}
}
mario.blitBitmap(screen,100,100);
Sulock(screen);
SDL_Flip(screen);
}

int main(int argc, char *argv[])
{

screen = initVideo (SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN,640,480,32);
mario.loadImage("mario.jpg");
if (mario.getImage()==NULL)
printf("Error loading bitmap.");
int done=0;

while(done == 0)
{
SDL_Event event;

while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) { done = 1; }

if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
}
}

DrawScene(screen);
}
mario.~image();
return 0;
}[/code]

Now in main.cpp, SDL_Surface* screen got weird errors. Here they are:

10 C:UsersTheronDocumentsC++SDLLearning SDLTestingmain.cpp expected init-declarator before '*' token

10 C:UsersTheronDocumentsC++SDLLearning SDLTestingmain.cpp expected `,' or `;' before '*' token

C:UsersTheronDocumentsC++SDLLearning SDLTestingmain.cpp In function `int SDL_main(int, char**)':

97 C:UsersTheronDocumentsC++SDLLearning SDLTestingmain.cpp `screen' undeclared (first use this function)

(Each undeclared identifier is reported only once for each function it appears in.)

C:UsersTheronDocumentsC++SDLLearning SDLTestingMakefile.win [Build Error] [main.o] Error 1

Any help? It just started when I added image.h.

Best Regards,
CodeKing

Comments

  • You're missing a semicolon. Possibly other errors, I haven't looked that far...
    [code]
    #ifndef _IMAGE_H_
    #define _IMAGE_H_

    #include
    #include
    class image {
    public:
    SDL_Surface* loadBitmapRWops(char *resourcefilename, char *bitmapfilename);
    void loadImage(char* filename);
    void blitBitmap(SDL_Surface *dest, Uint16 x, Uint16 y);
    image();
    virtual ~image();

    SDL_Surface* getImage();
    private:
    SDL_Surface* bitmap;
    }[red];[/red]
    #endif
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion