Hello everyone. I copied this program from a website, sorry don't know where, and when I compile the following code with #include<SDL/SDL.h> it gives me fatal error #1035: Can't find include file <SDL/SDL.h> and when I compile it with #include<SDL.h> it gives me error #2120: Redeclaration of 'SDL_main', previously declared at C:\Program Files\PellesC\Include\SDL_main.h(57); expected 'int __cdecl function(int, char * *)' but found 'int __cdecl function(void)'
okay here is the code#include <SDL/SDL.h>
#include <stdlib.h>
#include <math.h>
#define BALL_SIZE 256
#define TEX_SIZE 1024U
#define NUM_BALLS 8
#define NUM_STARS 256
struct point_t {
int x;
int y;
};
static void balls(SDL_Surface *s, unsigned int frames);
static void rotozoom(SDL_Surface *s, unsigned int frames);
static void stars(SDL_Surface *s);
int main(void) {
srand(0xDEADBEEF);
SDL_Surface *screen;
screen = SDL_SetVideoMode(640,480,32, SDL_SWSURFACE);
balls(screen, 850);
rotozoom(screen, 850);
}
static void balls(SDL_Surface *s, unsigned int frames) {
/* Metaballs a.k.a. blobs. The algorithm:
Loop through every ball:
Go through the light map x,y:
if lightmap x,y + ball x,y is under the limits, we add(w/ += operator) to screen x,y(ball position + lightmap x,y)
the value in lightmap x,y.
if the resulting value is > 255, then we actually just let it overflow. This creates the nice effect inside the ball.
*/
unsigned int h = BALL_SIZE/2; /* x,y of the center of the ball */
unsigned int px,py;
unsigned int x=0;
unsigned int y=0;
unsigned int i=0;
unsigned int *pp;
unsigned int f=0;
unsigned int p;
double sf = 0.0f; /* variable for fade-in/-out effect. */
/* Static arrays to save some space */
static unsigned int map[BALL_SIZE*BALL_SIZE];
static struct point_t ball[NUM_BALLS];
pp = (unsigned int*)s->pixels; /* "Pixel Pointer" to point to the surface pixels */
/* Generate the lightmap */
for(y=0;y<BALL_SIZE;y++) {
for(x=0;x<BALL_SIZE;x++) {
/* So: in the lightmap the strenght is defined by 1/(dist_from_center ^ 4) * size * 2^20(1 048 576) */
p = 1/( pow(sqrt((x-h)*(x-h)+(y-h)*(y-h)),4) +1 )*(BALL_SIZE<<20);
if(p>255) p = 255; /* Let's make sure the strenght won't overflow */
map[y*BALL_SIZE+x] = p;
}
}
/* Randomize the ball positions */
for(i=0;i<NUM_BALLS;i++) {
ball[i].x = BALL_SIZE+rand()%(640-(BALL_SIZE*2));
ball[i].y = BALL_SIZE+rand()%(480-(BALL_SIZE*2));
}
/* Let's loop until we've drawn enough frames */
while(f<frames) {
/* Fade in effect */
if(sf < 1.0 && f < 50) sf+=0.05;
/* Call the starfield */
stars(s);
/* Loop through every ball */
for(i=0;i<NUM_BALLS;i++) {
for(x=1;x<BALL_SIZE;x++) {
for(y=1;y<BALL_SIZE;y++) {
/* If and only if the x,y is inside the box .. */
if((y+ball[i].y) < 400 && y+ball[i].y > 80 && x+ball[i].x < 520 && x+ball[i].x > 120)
/* ..draw the pixel. The color is retrieved from the lightmap x,y. sf is the fade in/out multiplier. */
pp[(int)((y+ball[i].y)*640+(x+ball[i].x))] += (map[y*BALL_SIZE+x]*sf);
}
}
/* Let's make the balls float around */
px = (320-BALL_SIZE/2+(cos(f/18.6)*160*sf)) + sin(f/18.4+i)*80*sf;
py = (240-BALL_SIZE/2-(sin(f/21.4)*125*sf)) - cos(f/24.5+i)*60*sf;
ball[i].x = px;
ball[i].y = py;
}
/* Fade out effect */
if(frames-f < 150 && sf>0.012) sf-=0.0125;
/* Let's make sure we don't run too fast */
SDL_Delay(10);
SDL_Flip(s);
/* increase the framecount */
f++;
}
/* We're done. */
return;
}
static void stars(SDL_Surface *s) {
/*
This function handles the drawing and rotation of the background starfield, also draws the rectangle.
*/
static unsigned int i,x,y;
static unsigned int *pp;
static double v;
static struct point_t stars[NUM_STARS];
static unsigned int init;
/* If the stars haven't been initalized yet, then do it now */
if(!init) {
init=1;
for(i=0;i<NUM_STARS;i++) {
stars[i].x = -250+rand()%(250+640);
stars[i].y = -250+rand()%(250+480);
}
}
/* Increase the angle of the starfield */
v += 0.0075;
pp = (unsigned int*)s->pixels;
/* Let's clear the screen left out from the box, upper and lower segments */
memset(pp,0,80*640*4);
memset(pp+401*640,0,79*640*4);
/* And the same to the segments left to the sides of the box */
for(i=80;i<401;i++) {
memset(pp+(i*640),0,120*4);
memset(pp+(i*640+520), 0, 120*4);
}
for(i=0;i<NUM_STARS;i++) {
x = 320 + (stars[i].x*cos(v)+stars[i].y*sin(v));
y = 240 + (stars[i].y*cos(v)-stars[i].x*sin(v));
if(x>0 && x < 640 && y > 0 && y < 480) pp[y*640+x] = -1;
}
/* Let's draw the white rectangle. First the upper and lower borders. */
memset(pp+80*640+120, -1, 401*4);
memset(pp+400*640+120, -1, 401*4);
for(i=81;i<400;i++) {
/* Let's erase the stars inside the box */
memset(pp+i*640+121, 0, 400*4);
/* And draw the left and the right border of the box */
pp[i*640+120] = -1;
pp[i*640+520] = -1;
}
}
static void rotozoom(SDL_Surface *s, unsigned int frames) {
/*
At first this was supposed to be a rotozoomer with dynamic texture where the texture was created with a plasma effect...
Now, the effect is just a classical plasma effect where a texture is being applied on top of another texture and the two
textures are being rotated and moved around relative to each other. The speciality of this effect is that the textures are
being fit together with bitwise operators. The disorted image is achieved by using the same operators when creating the texture.
*/
unsigned int x, y, *pp, f=0,t=0;
/* Static to save some space */
static unsigned int col[512];
static unsigned int tex[TEX_SIZE*TEX_SIZE];
unsigned int x1, y1,x2,y2,fco,c;
unsigned char r,g,b;
double z=0.0, sf=0.0, tcos, tsin;
pp = (unsigned int*)s->pixels;
/* Generate random color palette */
for(x=0;x<512;x++) {
r = 192+sin(x/46.4)*95;
g = 64+cos(x/85.4)*48;
b = 16+sin(x/14.4)*4;
col[x] = r << 16 | g << 8 | b;
}
for(x=0;x<TEX_SIZE-1;x++) {
for(y=0;y<TEX_SIZE-1;y++) {
t = 128 + cos(x/37.9)*64 + sin(y/30.3)*64 - cos(x/35.3)*64 + sin((x&y)/4)*8; /* x^y brings in a small flavor of traditional XOR texture. */
tex[y*TEX_SIZE+x] = t;
}
}
while(f<frames) {
if(sf < 1.0 && f < 50) sf+=0.015;
z+=0.015;
stars(s);
/* Variable to make the effect more dynamic. */
fco = cos(f/16.4)*8 + sin(f/6.5)*12;
/* Let's precalculate these so we don't have to do that per-pixel */
tcos = cos(z);
tsin = sin(z);
x1 = 64+tcos*16 + tsin*12;
y1 = 64+tcos*16 + tsin*24;
/* Fade out effect */
if(frames-f < 75) sf/=1.075;
for(x=1;x<400;x++) {
for(y=1;y<320;y++) {
x2 = 560+(tcos*x+tsin*(y/2)); /* Rotations */
y2 = 560+(tcos*y-tsin*(x/2));
/* Calculate the color by adding two textures together by using bitwise AND operator. */
c = (col[tex[(x1+x)*TEX_SIZE+(y1+y)] + (tex[x2*TEX_SIZE+y2] & tex[y2*TEX_SIZE+x2])-fco]);
/* Let's break the color to it's RGB components. */
r = c >> 16 & 0xFF; g = c >> 8 & 0xFF, b = c & 0xFF;
/* Multiply the color components by the fade in/out multiplier and fuse them together */
pp[(y+80)*640+(x+120)] = (int)(sf*r) << 16 | (int)(sf*g) << 8 | (int)(sf*b);
}
}
/* Increase the framecount and slow down */
f++;
SDL_Delay(10);
SDL_Flip(s);
}
return;
}
Also, when I tried running the code with #include<SDL/SDL.h> it gave me error #2009: Conflicting argument declarations for function 'SDL_main'. and error #2048: Undeclared identifier 'DETECT'. When I ran it with #include<SDL.h> it gave me the same errors. Can anyone tell me what the fix for this is?
I really just want to make sure that I have all of the files necessary to do graphics, games and everything else you can do with sdl. Also, is there anything out there better for Pelles C inparticular than sdl? Thanks for the help.