SDL

Tratamos sobre el manejo de APIs frecuentemente utilizadas en el desarrollo de videojuegos, como SDL, pygame o SFML.

SDL

Notapor dsavatar » Jue Ene 28, 2010 10:14 pm

hola gente que tal?
miren yo andve leyendo el articulo que tenian en la pagina sobre imprimir fuentes utilizando la libreria sdl.
me salio con el primer ejemplo pero la cuestion es que primero necesito imprimir un string que va cambiando los valores, y el otro problema es que tengo un fondo en el juego, y al imprimir el texto para probar las letras vienen con fondo. Existe alguna manera de que solo imprima las letras y el fondo con el que vienen las fuentes sea transparente?
Desde ya gracias
Saludos
dsavatar
 
Mensajes: 1
Registrado: Jue Ene 28, 2010 10:00 pm

Notapor endaramiz » Jue Ene 28, 2010 11:25 pm

Sí que se puede hacer. Esa técnica se llama color key.
Según el artículo de la misma sección "Conceptos básicos para el desarrollo de videojuegos":
Cuando mostramos una imagen en pantalla, esta siempre se verá como un cuadrado o rectángulo, pero sabemos que dentro tiene la representación de un objeto, personaje, enemigo, ítem, etc. Al dibujar esta imagen queremos ver solo la forma que representa, para esto debemos elegir algún color transparente, pintar con ese color las zonas que no queremos que aparezcan y luego dibujar la imagen ignorando dicho color.

Normalmente se utiliza el color magenta (255, 0, 255), como color de transparencia, ya que es poco probable que se encuentre en una imagen.

Dependiendo de la API gráfica que utilicemos para desarrollar nuestro videojuego, tendremos una función que realice esta tarea, la de descartar un color determinado al dibujar la imagen.

Pero no solo usar un color como el magenta es la solución para no ver una imagen en su forma original, también podemos hacer uso de las propiedades del formato gráfico PNG (Portable Network Graphics), ya que este formato guarda un canal alpha con las partes transparentes de la imagen.


Si tienes problemas, ya comentarás que API usas para explicarlo de manera más precisa.

Saludos.
Avatar de Usuario
endaramiz
 
Mensajes: 283
Registrado: Vie Ago 31, 2007 9:25 am
Ubicación: Barcelona

Notapor Metalero » Vie Ene 29, 2010 5:29 pm

Respecto a lo de la string de largo variable...no veo donde esta la duda.

Con respecto a las fuentes "con fondo", es por que vos estas renderizando el texto usando SOLID seguramente. SDL_ttf, tiene 3 tipos de renders:

SOLID, SHADED, BLENDED.

Aca te dejo la descripcion de cada una segun el manua:

-----------------------------------------------------------------------------------------------------------
Solid: Quick and Dirty
Create an 8-bit palettized surface and render the given text at fast quality
with the given font and color. The pixel value of 0 is the colorkey, giving a
transparent background when blitted. Pixel and colormap value 1 is set to the
text foreground color. This allows you to change the color without having to
render the text again. Palette index 0 is of course not drawn when blitted to
another surface, since it is the colorkey, and thus transparent, though its actual
color is 255 minus each of the RGB components of the foreground color. This
is the fastest rendering speed of all the rendering modes. This results in no box
around the text, but the text is not as smooth. The resulting surface should blit
faster than the Blended one. Use this mode for FPS and other fast changing
updating text displays.

Shaded: Slow and Nice, but with a Solid Box
Create an 8-bit palettized surface and render the given text at high quality
with the given font and colors. The 0 pixel value is background, while other
pixels have varying degrees of the foreground color from the background color.
This results in a box of the background color around the text in the foreground
color. The text is antialiased. This will render slower than Solid, but in about
the same time as Blended mode. The resulting surface should blit as fast as
Solid, once it is made. Use this when you need nice text, and can live with a
box.

Blended: Slow Slow Slow, but Ultra Nice over another image
Create a 32-bit ARGB surface and render the given text at high quality, using
alpha blending to dither the font with the given color. This results in a surface
with alpha transparency, so you don’t have a solid colored box around the text.
The text is antialiased. This will render slower than Solid, but in about the
same time as Shaded mode. The resulting surface will blit slower than if you
had used Solid or Shaded. Use this when you want high quality, and the text
isn’t changing too fast.
-----------------------------------------------------------------------------------------------------------

En pocas palabras. Solid es rapido, pero sale con el fondo ese, y tiene una calidad mala.
Shaded tiene la misma calidad del Solid, pero podes ponerele un color de fondo, y luego seleccionarlo como color key, y asi sale trasparente, pero siempre quedan algunos vestigios del color de fondo sobre la fuente.
Blended, es de alta calidad, en 32 bits (los otros son en 8). No tiene fondo (el fondo es trasparente mediante alpha, creo). Pero consume bastante mas recursos del prosesador que los otros metodos.

Para usar estos metodos:

Código: Seleccionar todo
TTF RenderText_Solid(TTF_Font *font, const char *text,
SDL_Color fg)

TTF RenderText_Shaded(TTF_Font *font, const char *text,
SDL_Color fg, SDL_Color bg)

TTF RenderText_Blended(TTF_Font *font, const char *text,
SDL_Color fg)
Metalero
 
Mensajes: 14
Registrado: Sab Oct 24, 2009 3:47 pm


Volver a Sobre las bibliotecas multimedia

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados

cron