tBane Temat założony przez niniejszego użytkownika |
[SDL] PNG - czasami nie wczytuje obrazów » 2023-03-22 22:37:33 Witam. Otóż mam problem, polegający na tym, że SDL nie wszystkie obrazy PNG poprawnie wczytuje. Próbowałem problem na własną rękę rozwiązać i konwerterowac wszystkie grafiki na BMP i z powrotem na PNG ale nadal się wykrzacza. Korzystałem z kilku internetowych konwerterów. Pliki tworzylem wczesniej w paincie i niektore wczytuje poprawnie, tak jak te z "cyframi". Moze padlem ofiarą wirusa i to jakaś iniekcja kodu? da się to jakoś zweryfikować? Ma ktos link do porzadnego konwertera lub jakis sposob na SDL? link do tekstur https://drive.google.com/drive/folders/1wG-J7ksax_giBVVjA0ZzqWBASNBxDO5J?usp=share_link
screenshot |
|
pekfos |
» 2023-03-22 22:53:59 Po prostu masz błąd w kodzie. |
|
tBane Temat założony przez niniejszego użytkownika |
» 2023-03-22 22:54:15 INICJALIZACJA SDL void initSDL() { SDL_Init( SDL_INIT_EVERYTHING ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 0 ); SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 8 ); SDL_DisplayMode DM; SDL_GetCurrentDisplayMode( 0, & DM ); screenWidth = DM.w; screenHeight = DM.h; window = SDL_CreateWindow( "Minesweeper", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screenWidth, screenHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN ); SDL_GL_CreateContext( window ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glEnable( GL_BLEND ); }
SHADERY ORAZ WCZYTYWANIE/RYSOWANIE TEKSTUR const char * vTextureSource = "attribute vec4 position;\n" "attribute vec2 texcoord;\n" "varying vec2 Texcoord;\n" "void main()\n" "{\n" "gl_Position = position;\n" "Texcoord = texcoord;\n" "}\n";
const char * fTextureSource = "precision mediump float;\n" "uniform sampler2D texture;\n" "varying vec2 Texcoord;\n" "void main()\n" "{\n" "gl_FragColor = texture2D(texture, Texcoord);\n" "}\n";
GLuint vTextureShader; GLuint fTextureShader; GLuint textureProgram; void initShader() { vTextureShader = glCreateShader( GL_VERTEX_SHADER ); fTextureShader = glCreateShader( GL_FRAGMENT_SHADER ); glShaderSource( vTextureShader, 1, & vTextureSource, NULL ); glShaderSource( fTextureShader, 1, & fTextureSource, NULL ); glCompileShader( vTextureShader ); glCompileShader( fTextureShader ); textureProgram = glCreateProgram(); glAttachShader( textureProgram, vTextureShader ); glAttachShader( textureProgram, fTextureShader ); glLinkProgram( textureProgram ); }
void loadTexture( GLuint & texture, string path ) { cout << "loading texture: " << path << "\n"; SDL_Surface * img = IMG_Load( path.c_str() ); if( img == NULL ) { cout << "cant load texture\n"; return; } glGenTextures( 1, & texture ); glBindTexture( GL_TEXTURE_2D, texture ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, img->w, img->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->pixels ); cout << "done\n"; SDL_FreeSurface( img ); }
void drawRectTex( int screenWidth, int screenHeight, int posX, int posY, int width, int height, GLuint texture ) { float v1x, v1y, v2x, v2y, v3x, v3y, v4x, v4y; v1x = float( posX ) - float( width ) / 2.f; v1y = float( posY ) + float( height ) / 2.f; v2x = float( posX ) + float( width ) / 2.f; v2y = float( posY ) + float( height ) / 2.f; v3x = float( posX ) + float( width ) / 2.f; v3y = float( posY ) - float( height ) / 2.f; v4x = float( posX ) - float( width ) / 2.f; v4y = float( posY ) - float( height ) / 2.f; static GLfloat vertexes[ 6 ]; static GLfloat texCoords[ 6 ]; GLint textureUniform, position, texcoord; glUseProgram( textureProgram ); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, texture ); textureUniform = glGetUniformLocation( textureProgram, "texture" ); glUniform1i( textureUniform, 0 ); vertexes[ 0 ] = v1x * 2 / float( screenWidth ); vertexes[ 1 ] = v1y * 2 / float( screenHeight ); vertexes[ 2 ] = v2x * 2 / float( screenWidth ); vertexes[ 3 ] = v2y * 2 / float( screenHeight ); vertexes[ 4 ] = v3x * 2 / float( screenWidth ); vertexes[ 5 ] = v3y * 2 / float( screenHeight ); texCoords[ 0 ] = 0; texCoords[ 1 ] = 0; texCoords[ 2 ] = 1; texCoords[ 3 ] = 0; texCoords[ 4 ] = 1; texCoords[ 5 ] = 1; position = glGetAttribLocation( textureProgram, "position" ); glEnableVertexAttribArray( position ); glVertexAttribPointer( position, 2, GL_FLOAT, GL_FALSE, 0, vertexes ); texcoord = glGetAttribLocation( textureProgram, "texcoord" ); glEnableVertexAttribArray( texcoord ); glVertexAttribPointer( texcoord, 2, GL_FLOAT, GL_FALSE, 0, texCoords ); glDrawArrays( GL_TRIANGLES, 0, 4 ); vertexes[ 0 ] = v1x * 2 / float( screenWidth ); vertexes[ 1 ] = v1y * 2 / float( screenHeight ); vertexes[ 2 ] = v3x * 2 / float( screenWidth ); vertexes[ 3 ] = v3y * 2 / float( screenHeight ); vertexes[ 4 ] = v4x * 2 / float( screenWidth ); vertexes[ 5 ] = v4y * 2 / float( screenHeight ); texCoords[ 0 ] = 0; texCoords[ 1 ] = 0; texCoords[ 2 ] = 1; texCoords[ 3 ] = 1; texCoords[ 4 ] = 0; texCoords[ 5 ] = 1; position = glGetAttribLocation( textureProgram, "position" ); glEnableVertexAttribArray( position ); glVertexAttribPointer( position, 2, GL_FLOAT, GL_FALSE, 0, vertexes ); glDrawArrays( GL_TRIANGLES, 0, 4 ); texcoord = glGetAttribLocation( textureProgram, "texcoord" ); glEnableVertexAttribArray( texcoord ); glVertexAttribPointer( texcoord, 2, GL_FLOAT, GL_FALSE, 0, texCoords ); glDrawArrays( GL_TRIANGLES, 0, 4 ); }
|
|
tBane Temat założony przez niniejszego użytkownika |
» 2023-03-22 22:59:36 No właśnie z 2h siedziałem przy tym, funkcje rysujące są sprawdzone, bo w innych projektach działają. Nie dzialaja mi pliki buttonLarge, flag, question, mine, close w kilku roznych motywach graficznych, a zrobilem ich z ponad 10... zmieniałem także kolejność wczytywania tekstur, także nic to nie dało. |
|
pekfos |
» 2023-03-22 23:08:22 Spróbuj glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, img->w, img->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->pixels );
glFlush(); cout << "done\n"; SDL_FreeSurface( img ); |
|
tBane Temat założony przez niniejszego użytkownika |
» 2023-03-22 23:13:19 glFlush nie pomogl :-/ |
|
pekfos |
» 2023-03-22 23:58:50 Sprawdź czy te obrazy na pewno są w RGBA (img->format) i pewnie nie zaszkodzi robić SDL_LockSurface() przed dostępem do img->pixels. |
|
tBane Temat założony przez niniejszego użytkownika |
» 2023-03-23 01:21:59 zrobiłem jak radziłeś, istotnie format się różnił. dla tekstur z cyframi byl ABGR8888 dla reszty INDEX8. Czyli teraz zmienić format danych w GL_TEXTURE_2D? cout << "loading texture: " << path << "\n"; SDL_Surface * img = IMG_Load( path.c_str() ); if( img == NULL ) { cout << "cant load texture\n"; return; }
cout << "format: " << img->format->format << "\n"; cout << SDL_GetPixelFormatName( img->format->format );
...
loading texture: Themes/00_Standard/0.png format: 376840196 SDL_PIXELFORMAT_ABGR8888done
loading texture: Themes/00_Standard/1.png format: 376840196 SDL_PIXELFORMAT_ABGR8888done
loading texture: Themes/00_Standard/2.png format: 376840196 SDL_PIXELFORMAT_ABGR8888done
loading texture: Themes/00_Standard/3.png format: 376840196 SDL_PIXELFORMAT_ABGR8888done
loading texture: Themes/00_Standard/4.png format: 376840196 SDL_PIXELFORMAT_ABGR8888done
loading texture: Themes/00_Standard/5.png format: 376840196 SDL_PIXELFORMAT_ABGR8888done
loading texture: Themes/00_Standard/6.png format: 376840196 SDL_PIXELFORMAT_ABGR8888done
loading texture: Themes/00_Standard/7.png format: 376840196 SDL_PIXELFORMAT_ABGR8888done
loading texture: Themes/00_Standard/8.png format: 376840196 SDL_PIXELFORMAT_ABGR8888done
loading texture: Themes/00_Standard/Bad.png format: 318769153 SDL_PIXELFORMAT_INDEX8done
loading texture: Themes/00_Standard/ButtonLarge.png format: 376840196 SDL_PIXELFORMAT_ABGR8888done
loading texture: Themes/00_Standard/ButtonSmall.png format: 376840196 SDL_PIXELFORMAT_ABGR8888done
loading texture: Themes/00_Standard/Close.png format: 318769153 SDL_PIXELFORMAT_INDEX8done
loading texture: Themes/00_Standard/Explosion.png format: 318769153 SDL_PIXELFORMAT_INDEX8done
loading texture: Themes/00_Standard/Flag.png format: 318769153 SDL_PIXELFORMAT_INDEX8done
loading texture: Themes/00_Standard/Mine.png format: 318769153 SDL_PIXELFORMAT_INDEX8done
loading texture: Themes/00_Standard/Question.png format: 318769153 SDL_PIXELFORMAT_INDEX8done
|
|
« 1 » 2 |