I just started with SDL in c++ and VS 2013 Community. I want to draw a circle and so i searched on Google and found http://content.gpwiki.org/index.php/SDL:Tutorials:Drawing_and_Filling_Circles. But as I tried to implement it in a seperate fill_circle.cpp file, include this in my main.cpp and call the function, I get the Error that said function fill_circle() is already defined in fill_circle.obj and that there are conflicts with other libs. So I tried to implement the drawning function directly into my main.cpp but i get a similar error, saying that void __cdecl fill_circle(struct SDL_Surface *,int,int,int,unsigned int) is already defined in fill_circle.obj.
I dont know what to do with those errors and hope someone of you can help me :)
EDIT: After completly removing the fill_circle.cpp and debug folder and implementing the Function in main.cpp the programm will compile but throw an error at runtime.
My main.cpp:
#include <SDL.h>
#include <iostream>
#include <cmath>
void fill_circle(SDL_Surface *surface, int cx, int cy, int radius, Uint32 pixel)
{
static const int BPP = 4;
double r = (double)radius;
for (double dy = 1; dy <= r; dy += 1.0)
{
// This loop is unrolled a bit, only iterating through half of the
// height of the circle. The result is used to draw a scan line and
// its mirror image below it.
// The following formula has been simplified from our original. We
// are using half of the width of the circle because we are provided
// with a center and we need left/right coordinates.
double dx = floor(sqrt((2.0 * r * dy) - (dy * dy)));
int x = cx - dx;
// Grab a pointer to the left-most pixel for each half of the circle
Uint8 *target_pixel_a = (Uint8 *)surface->pixels + ((int)(cy + r - dy)) * surface->pitch + x * BPP;
Uint8 *target_pixel_b = (Uint8 *)surface->pixels + ((int)(cy - r + dy)) * surface->pitch + x * BPP;
for (; x <= cx + dx; x++)
{
*(Uint32 *)target_pixel_a = pixel;
*(Uint32 *)target_pixel_b = pixel;
target_pixel_a += BPP;
target_pixel_b += BPP;
}
}
}
int main(int argc, char *argv[])
{
//Main loop flag
bool b_Quit = false;
//Event handler
SDL_Event ev;
//SDL window
SDL_Window *window = NULL;
SDL_Surface *windowSurface;
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
std::cout << "Video Initialisation Error: " << SDL_GetError() << std::endl;
}
else
{
window = SDL_CreateWindow("SDL_Project", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_SHOWN);
if (window == NULL)
{
std::cout << "Window Creation Error: " << SDL_GetError() << std::endl;
}
else
{
windowSurface = SDL_GetWindowSurface(window);
fill_circle(windowSurface, 10, 10, 20, 0xffffffff);
//Main loop
while (!b_Quit)
{
//Event Loop
while (SDL_PollEvent(&ev) != 0)
{
//Quit Event
if (ev.type == SDL_QUIT)
{
b_Quit = true;
}
}
SDL_UpdateWindowSurface(window);
}
}
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}