SDL_CreateRGBSurface
및 SDL_FillRect
함수 인 을 사용하여 텍스처를 만들려고하고 있지만 슬프게도 실패합니다. 나가 얻는 모두는 까만 직사각형이다.OpenGL 텍스처를 사용하는 SDL_CreateRGBSurface가 검은 텍스처를 생성합니다.
내가 (IMG_Load
와 파일에서로드 텍스처를 위해 노력하고 있습니다) 코드의 조각 다음 사용하고 그 작업을 달성하기
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
rect = SDL_CreateRGBSurface(SDL_SWSURFACE, _w,_h,24,rmask,gmask,bmask,amask);
if(rect == NULL) {
fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError());
exit(1);
}
Uint32 color = SDL_MapRGBA(rect->format,255,255,0,126);
SDL_FillRect(rect,NULL,color);
render.load(rect);
텍스처 로딩에 앉아 코드를 다음과 같이를
void Texture::load(SDL_Surface* surface){
ogl_check_error("surface load");
GLenum texture_format;
GLint nOfColors;
if ( surface ) {
// get the number of channels in the SDL surface
nOfColors = surface->format->BytesPerPixel;
if (nOfColors == 4) // contains an alpha channel
{
if (surface->format->Rmask == 0x000000ff)
texture_format = GL_RGBA;
else
texture_format = GL_BGRA;
} else if (nOfColors == 3){ // no alpha channel
if (surface->format->Rmask == 0x000000ff)
texture_format = GL_RGB;
else
texture_format = GL_BGR;
}else {
cerr<<"bad surface"<<endl;
exit(1);
}
// Have OpenGL generate a texture object handle for us
glGenTextures(1, &texture);
// Bind the texture object
glBindTexture(GL_TEXTURE_2D, texture);
// Set the texture's stretching properties
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Edit the texture object's image data using the information SDL_Surface gives us
glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0,
texture_format, GL_UNSIGNED_BYTE, surface->pixels);
}
else {
printf("SDL could not load image.bmp: %s\n", SDL_GetError());
SDL_Quit();
exit(1);
}
ogl_check_error("after surface load");
width = surface->w;
height = surface -> h;
}