For your first, there’s a good chance that you’re not taking endianness
into account for your colour stuff. Here is how I did it (thanks to many
people here on the mailing list);
https://github.com/mrozbarry/bitfighter-experiments/blob/master/bitfighter1.0/sdlutil.cpp#L349
Second, your best bet is probably SDL_image, an add-on library to SDL,
found here: http://www.libsdl.org/projects/SDL_image/
I hope that helps,
-Alex
**
Hi, I am new to SDL (v 1.2.15) and have two problems with this code:
Code:
#include **
void Mesh::createTextures() {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface *surface;
surface = SDL_LoadBMP("…\…\resources\textures\bla.bmp");
int mode;
if (surface->format->BytesPerPixel == 3) { // RGB 24bit
mode = GL_RGB;
} else if (surface->format->BytesPerPixel == 4) { // RGBA 32bit
mode = GL_RGBA;
}
glGenTextures(1, &_textureID);
glBindTexture(GL_TEXTURE_2D, _textureID);
glTexImage2D(GL_TEXTURE_2D, 0, mode, surface->w, surface->h, 0, mode,
GL_UNSIGNED_BYTE, surface->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
First:
A texture which is completely red is shown blue. When I change the second
mode to GL_BGR though OpenGL renders nothing.
Short story:
The internalFormat parameter to glTexImage2D() is wrong, should be
GL_RGB/GL_RGBA.
Long story:
The internal format is best thought of “how should the graphics card keep
it” – it isn’t meant to communicate stuff like component order, but a more
abstract “does it have alpha?” “does it use 8 bits per component?”. The
graphics card will do whatever it wants with your data to make rendering
efficient. Maybe that means 8x8 tiled textures with GARB format or
something weird. In short, your call could should be:
glTexImage2D(GL_TEXTURE_2D, 0,
surface->format->BytesPerPixel == 4? GL_RGBA : GL_RGB, /* Internal format */
, surface->w, surface->h, 0,
surface->format->BytesPerPixel == 4?, GL_BGRA : GL_BGR, /* External format
*/
GL_UNSIGNED_BYTE, surface->pixels);
Next time you get weird OpenGL issues, try glGetError();
http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml
GL_INVALID_VALUE is generated if internalFormat is not 1, 2, 3, 4, or one
of the accepted resolution and format symbolic constants.
Patrick
Second:On Wed, Jun 6, 2012 at 9:43 AM, Alex Barry <alex.barry at gmail.com> wrote:
On Wed, Jun 6, 2012 at 3:47 AM, telandor wrote:
How can I load other images than BMP? I can only find the function
SDL_LoadBMP().
I hope anybody can help me out with this.
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org