here is the function I use for converting sdl surfaces into opengl textures, hope that helps.
though I bet there are problems on little-endian machines with it. not sure though.
GLuint load(SDL_Surface* pSurface) {
SDL_Surface* surface = pSurface; // Copy surface pointer to temporary pointer, so that we don’t change original surface
surface = SDL_DisplayFormatAlpha(surface); // Convert it into display format
if (!surface) {
printf("WARNING: Could not load Texture");
return EXIT_FAILURE;
}
GLuint texture_id = 0;
glGenTextures(1, &texture_id); // Generate a openGL texture
glBindTexture(GL_TEXTURE_2D, texture_id); // Tell openGL to use the current texture
// Copy pixel data from the SDL surface into the texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, surface->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Define behaviour at resize
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // ...
return texture_id; // All done properly, return OpenGL texture ID
}
Glenn McCord schrieb:> I’m finding it difficult to find information on how to go about using
text in an OpenGL+SDL environment.
I can blit stuff onto a surface for a 2D world, but I’m of the
understanding that I then need to convert an SDL surface into a
texture (or something) for use with texture mapping.
I can fget as far as creating a text surface using:
TTF_Init();
TTF_Font* font = TTF_OpenFont(“ARIAL.TTF”, 12);
SDL_Color foregroundColor = { 255, 255, 255 };
SDL_Color backgroundColor = { 0, 0, 255 };
SDL_Surface* textSurface = TTF_RenderText_Shaded(font, “This is my
text.”, foregroundColor, backgroundColor);
SDL_Rect textLocation = { 100, 100, 0, 0 };
SDL_Event event;
bool gameRunning = true;
while (isRunning
{
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
SDL_BlitSurface(textSurface, NULL, screen, &textLocation);
SDL_Flip(screen);
}
etc
So how do I go about converting the surface to a texture map?
If there are other font libraries that can be used with PSPGL for the
PSP, let me know but I think I’m stuck with SDL_ttf. I actually need
text for debugging.
Cheers
Glenn
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
–
Jessica