방금 C++ 및 VS 2013 커뮤니티에서 SDL로 시작했습니다. 원을 그리기 위해 Google에서 검색하여 http://content.gpwiki.org/index.php/SDL:Tutorials:Drawing_and_Filling_Circles을 찾았습니다. 그러나 필자가 별도의 fill_circle.cpp 파일에 구현하려고 할 때 main.cpp에이 파일을 포함하고 함수를 호출하면 fill_circle.obj 함수에 fill_circle() 함수가 이미 정의되어 있고 충돌이 있다고하는 오류가 발생합니다. 다른 libs. 그래서 main.cpp에 직접 drawing 함수를 구현하려고 시도했지만 void __cdecl fill_circle (struct SDL_Surface *, int, int, int, unsigned int)가 fill_circle.obj에 이미 정의되어 있다는 비슷한 오류가 발생합니다. 내가 이러한 오류와 함께 할 당신의 누군가가 나 :서클 그리기 및 채우기
편집을 도울 수 있기를 바랍니다 무엇을 잘 모릅니다
: completly fill_circle.cpp 및 디버그 폴더를 제거하고을 programm 것 MAIN.CPP의 기능을 구현 한 후 컴파일하지만 런타임시 오류가 발생합니다.
내 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;
}
변경 함수 이름 - Pauls_fill_Circle'에()', 당신이 네임 스페이스 ambigutity의 결과를보고있는 것 같다 빠른 눈에서. –
여전히 런타임 오류가 발생합니다. SDL_Project.exe의 0x011F6CF9에서 첫 번째 예외가 발생했습니다. 0xC0000005 : 0x03604C10 위치 쓰기 액세스 위반입니다. 이 예외 처리기가 있으면 프로그램을 안전하게 계속할 수 있습니다. – Phorskin
fill_circle (windowSurface, 10, 10, 20, 0xffffffff); 표면 바깥 쪽을 끌고 프로그램이 충돌합니다. – Martin