내 주요 목표는 주어진 텍스처의 픽셀 데이터를 읽는 것이므로 테스트하려면 대상 액세스로 새 텍스처를 만든 다음 빨간색으로 그립니다.왜 SDL2에서 텍스처를 그릴 수 없습니까?
문제는 픽셀 데이터에 액세스 할 때 SDL_RenderReadPixels()에서 피치가 0이고 모든 픽셀 데이터가 0이라고 문제가 있다는 것입니다. 또한 새 텍스처를 그리려고하면 검정색으로 표시됩니다.
SDL_Texture* tempChar = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 3, 5);
if (SDL_SetRenderTarget(renderer, tempChar) != 0) {
cout << "SDL_SetRenderTarget() Error! " << SDL_GetError() << endl;
} else {
cout << "SDL_SetRenderTarget() success" << endl;
}
if (SDL_RenderClear(renderer) != 0) {
cout << "SDL_RenderClear() Error! " << SDL_GetError() << endl;
} else {
cout << "SDL_RenderClear() success" << endl;
}
if (SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255) != 0) {
cout << "SDL_SetRenderDrawColor() Error! " << SDL_GetError() << endl;
} else {
cout << "SDL_SetRenderDrawColor() success" << endl;
}
if (SDL_RenderFillRect(renderer, NULL) != 0) {
cout << "SDL_RenderClear() Error! " << SDL_GetError() << endl;
} else {
cout << "SDL_RenderClear() success" << endl;
}
int w;
int h;
Uint32 format;
int access;
if (SDL_QueryTexture(tempChar, &format, &access, &w, &h) != 0) {
cout << "SDL_QueryTexture() ERROR : " << SDL_GetError() << endl;
} else {
cout << "SDL_QueryTexture() no error" << endl;
}
cout << "width is : " << w << " height is : " << h << endl;
if (access == SDL_TEXTUREACCESS_TARGET) {
cout << "TARGET" << endl;
}
if (format == SDL_PIXELFORMAT_RGBA8888) {
cout << "format is : SDL_PIXELFORMAT_RGBA8888" << endl;
}
void* readPixels = NULL;
int pitch;
if (SDL_RenderReadPixels(renderer, NULL, 0, readPixels, pitch) != 0) {//12 pitch, 3x4bytes
//an error occurred
cout << "SDL_RenderReadPixels() Error, text probably wont work... :-/\n" << SDL_GetError() << endl;
} else {
cout << "SDL_RenderReadPixels() success" << endl;
}
cout << "pitch returned : " << pitch << endl;
menuMouse = tempChar;
for (int i = 0; i < 5; i++) {
cout << "i is : " << i << endl;
char* rowStart = ((char*) readPixels) + i * pitch;
cout << "pix data is : " << int(rowStart) << endl;
}
아아아, 그렇습니다. 정확하게 픽셀 데이터에 대해 가정 한 내용입니다. 문서는 실제로 어느 쪽이든 말하지 않습니다. 그리고 피치에 관해서는, 내가 얼마나 바보인지. 문서 작성을위한 더 좋은 곳이 있습니까? [link] (https://wiki.libsdl.org/SDL_RenderReadPixels) 위키는 매우 구체적으로 보입니다. – Tristus
@Tristus 미안하지만 나는 정말로 그것을 찾지 못했습니다. 의심의 여지가없고 wiki가 짧아지면 소스 코드를 살펴 보는 것이 더 좋습니다. – keltar