这是之前的: http ://img22.imageshack.us/img22/5310/beforedes.jpg之后: http ://img189.imageshack.us/img189/8890/afterr.jpg
编辑::现在我看看imageshack的上传,文物减少了很多..但相信我,他们比那更明显。
我不明白为什么会这样。 Imageshack将它们上传到jpg,但是在我的程序中,它们在图像文件夹中作为.tif(.tif的原因是因为我无法获得任何其他图像来维护它们的透明部分)。
但无论如何,这些文物跟随图像的原始顶部,因为它旋转除原始之外的任何地方。
这是加载图像的代码的一部分
GLuint texture; GLenum texture_format; GLint nofcolors; GLfloat spin; bool Game::loadImage() { SDL_Surface * surface; // this surface will tell us the details of the image if ( surface = SM.load_image("Images/tri2.tif") ) { //get number of channels in the SDL surface nofcolors = surface->format->BytesPerPixel; //contains an alpha channel if ( nofcolors == 4 ) { 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; } // 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 ); glTexImage2D( GL_TEXTURE_2D, 0, nofcolors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels ); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } else { SDL_Quit(); return false; } // Free the SDL_Surface only if it was successfully created if ( surface ) { SDL_FreeSurface( surface ); return true; } else return false; } void Game::drawImage() { // Clear the screen before drawing glClear( GL_COLOR_BUFFER_BIT ); glTranslatef( float(S_WIDTH/2), float(S_HEIGHT/2), 0.0f ); glRotatef( spin, 0.0, 0.0, 1.0 ); // Bind the texture to which subsequent calls refer to glBindTexture( GL_TEXTURE_2D, texture ); glBegin( GL_QUADS ); { // Top-left vertex (corner) glTexCoord2i( 0, 0 ); glVertex3f( -64, 0, 0 ); // Top-right vertex (corner) glTexCoord2i( 1, 0 ); glVertex3f( 64, 0, 0 ); // Bottom-right vertex (corner) glTexCoord2i( 1, 1 ); glVertex3f( 64, 128, 0 ); // Bottom-left vertex (corner) glTexCoord2i( 0, 1 ); glVertex3f( -64, 128, 0 ); } glEnd(); glLoadIdentity(); SDL_GL_SwapBuffers(); }This is the before: http://img22.imageshack.us/img22/5310/beforedes.jpg znd after: http://img189.imageshack.us/img189/8890/afterr.jpg
EDIT:: Now that I look at imageshack's upload, the artifacts are diminished a great deal.. but trust me, they are more pronounced than that.
I don't understand why this is happening. Imageshack uploads them to jpg, but in my program they are in the image folder as .tif (The reason for .tif is because I couldn't get ANY other image to maintain their transparent parts).
But anyways, these artifacts follow the original top of the image as it rotates anywhere except the original.
Here's part of my code that loads the image
GLuint texture; GLenum texture_format; GLint nofcolors; GLfloat spin; bool Game::loadImage() { SDL_Surface * surface; // this surface will tell us the details of the image if ( surface = SM.load_image("Images/tri2.tif") ) { //get number of channels in the SDL surface nofcolors = surface->format->BytesPerPixel; //contains an alpha channel if ( nofcolors == 4 ) { 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; } // 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 ); glTexImage2D( GL_TEXTURE_2D, 0, nofcolors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels ); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } else { SDL_Quit(); return false; } // Free the SDL_Surface only if it was successfully created if ( surface ) { SDL_FreeSurface( surface ); return true; } else return false; } void Game::drawImage() { // Clear the screen before drawing glClear( GL_COLOR_BUFFER_BIT ); glTranslatef( float(S_WIDTH/2), float(S_HEIGHT/2), 0.0f ); glRotatef( spin, 0.0, 0.0, 1.0 ); // Bind the texture to which subsequent calls refer to glBindTexture( GL_TEXTURE_2D, texture ); glBegin( GL_QUADS ); { // Top-left vertex (corner) glTexCoord2i( 0, 0 ); glVertex3f( -64, 0, 0 ); // Top-right vertex (corner) glTexCoord2i( 1, 0 ); glVertex3f( 64, 0, 0 ); // Bottom-right vertex (corner) glTexCoord2i( 1, 1 ); glVertex3f( 64, 128, 0 ); // Bottom-left vertex (corner) glTexCoord2i( 0, 1 ); glVertex3f( -64, 128, 0 ); } glEnd(); glLoadIdentity(); SDL_GL_SwapBuffers(); }最满意答案
看起来纹理设置为GL_WRAP 。 请尝试GL_CLAMP_TO_EDGE 。
Looks like the texture is set to GL_WRAP. Try GL_CLAMP_TO_EDGE instead.
更多推荐
发布评论