Jump to content
  • Advertisement
Sign in to follow this  
K0K0NUT_h3lmut

Is this possible?

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

I know I'm missing something. What's wrong with this:
#include <allegro.h>

void main(void)
{
allegro_init();
install_keyboard();
//initialize random # seed
srand(time(NULL));
set_color_depth(colordepth);
ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);     

if (ret != 0) 
{
allegro_message(allegro_error);
return 1;
}


char *filename = "bubble2.pcx";
int colordepth = 32;
BITMAP *image;
int SCREEN_W=640
int SCREEN_H=480
int ret;
int x;
int y;
x = rand() % SCREEN_W;
y = rand() % SCREEN_H;

//load the image file
image = load_bitmap(filename, NULL);
if (!image)
{
allegro_message("Error loading %s", filename);
return 1;
}

//display the image
blit(image, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

blit(image, image, 0, 0, 0, 0, x, y);


//end program
return 0;
}
END_OF_MAIN()

[Edited by - K0K0NUT_h3lmut on July 25, 2005 9:38:33 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You could, I dunno, tell us what isn't happening that should. Will it not compile? What compiler errors are there if it doesn't compile? Does it compile and not work? What does it do if it compiles?

Share this post


Link to post
Share on other sites
Call me dense, but what's that END_OF_MAIN(); doing floating off by itself, outside the main() code block? Could be your compiler is expecting you to define the END_OF_MAIN() routine.

I could be wrong, though, I've never used Allegro.

Share this post


Link to post
Share on other sites
lol...srry, I was a little distracted. It compiles. When I run it though. It gives me a windows message error with the "send" and "don't send" options(Windows XP). now when I compile it it gives me: "[Linker error] undefined reference to WinMain16@", "Id returned 1 exit status", [Build Error] [Project1.exe]Error 1.".

Share this post


Link to post
Share on other sites
Use a debugger.


Program received signal SIGFPE, Arithmetic exception.
[Switching to Thread 16384 (LWP 12814)]
0x0804cdd5 in main () at foo.cpp:12
12 x = rand() % SCREEN_W;
(gdb) print SCREEN_W
$1 = 0


% returns the remainder of a division, SCREEN_W is 0 because the graphics mode hasn't been set yet, and so you're dividing by zero, hence it explodes.

Also, what the heck are you expecting blit(image, image, 0, 0, 0, 0, x, y); to do? And why do you assign random numbers to x and y and then seed the random number generator. Strangeness.

Share this post


Link to post
Share on other sites
Please use the
...
tags. It makes it so much easier to organize and display your code.

What IDE/Compiler are you using? If you are using MSVC++, I know they have a nice debugger. This way you can trace each variable in your program, set breakpoints, etc.

Share this post


Link to post
Share on other sites
Quote:
Original post by smart_idiot
Use a debugger.


Program received signal SIGFPE, Arithmetic exception.
[Switching to Thread 16384 (LWP 12814)]
0x0804cdd5 in main () at foo.cpp:12
12 x = rand() % SCREEN_W;
(gdb) print SCREEN_W
$1 = 0


% returns the remainder of a division, SCREEN_W is 0 because the graphics mode hasn't been set yet, and so you're dividing by zero, hence it explodes.

Also, what the heck are you expecting blit(image, image, 0, 0, 0, 0, x, y); to do? And why do you assign random numbers to x and y and then seed the random number generator. Strangeness.


Well, what i was trying to do was copy part of an image and then randomly display it on the image it was copied from.I guess you could say I was trying to do picture within picture. Although, considering my noobness, crazy work environment, and these games lying near me I'm not doin' to good of a job. I changed the source code(as you can see in the above edit)... it still DOESN'T work!!!

edit: I am using Bloodshed, but I have zero experience debugging...

Share this post


Link to post
Share on other sites
You're fired for having the main function return void.

Quote:

I guess you could say I was trying to do picture within picture.


I don't follow.

Share this post


Link to post
Share on other sites
how come you are returning either a one or 0 when you have: void main(void)

this should be: int main(void)

Share this post


Link to post
Share on other sites
Quote:
Original post by poss74
Call me dense, but what's that END_OF_MAIN(); doing floating off by itself, outside the main() code block? Could be your compiler is expecting you to define the END_OF_MAIN() routine.

I could be wrong, though, I've never used Allegro.


END_OF_MAIN() is a macro used to tell Allegro to tell the OS that the main() function is over, it's required or else the compiler will yell at you.

Also, as for the original post...

you cannot do either of

set_color_depth(colordepth);
ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);

if you haven't already initialized the variables ret and colordepth, which you don't do until after you use those commands.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!