Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: JORGE BAAK en 8 Marzo 2011, 18:30 pm



Título: SDL insertar imagenes [lenjuage C]
Publicado por: JORGE BAAK en 8 Marzo 2011, 18:30 pm
Hola amigos ando iniciando en DevC++ con SDL y hay un codigo ejemplo que trae entonces quiero modificarlo e insertar una imagen, pero como? es posible?..

Ando iniciando en este mundo del SDL :rolleyes: :rolleyes:


Código:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SDL/SDL.h>
#include <windows.h>

/*
 PLEASE NOTE: the program will require SDL.dll which is located in
              dev-c++'s dll directory. You have to copy it to you
  program's home directory or the path.
 */

/* The screen surface */
SDL_Surface *screen = NULL;


/* This function draws to the screen; replace this with your own code! */
static void
draw ()
{
    static int direction = 0;
    static int value = 0;
    static int which = 0;
    SDL_Rect rect;
    Uint32 color;

    /* Create a black background */
    color = SDL_MapRGB (screen->format, 0, 0, 0);
    SDL_FillRect (screen, NULL, color);

    /* Determine which color the layer should have */
    if (direction == 0)
    {
        value += 2;
        if (value >= 256)
        {
            value = 255;
            direction = 1;
        }
    }
    else
    {
        value -= 2;
        if (value <= 5)
        {
            value = 0;
            direction = 0;
            which++;
            if (which == 5)
                which = 0;
        }
    }

    /* Draw a layer with variable color */
    switch (which)
    {
      case 0:
          color = SDL_MapRGB (screen->format, value, 0, 0);
          break;
      case 1:
          color = SDL_MapRGB (screen->format, 0, value, 0);
          break;
      case 2:
          color = SDL_MapRGB (screen->format, 0, 0, value);
          break;
      case 3:
          color = SDL_MapRGB (screen->format, value, value, value);
          break;
      case 4:
          color = SDL_MapRGB (screen->format, value, 0, value);
          break;
    }

    rect.w = screen->w / 2;
    rect.h = screen->h / 2;
    rect.x = (screen->w / 2) - (rect.w / 2);
    rect.y = (screen->h / 2) - (rect.h / 2);
    SDL_FillRect (screen, &rect, color);


    /* Make sure everything is displayed on screen */
    SDL_Flip (screen);
    /* Don't run too fast */
    SDL_Delay (3);
}


int
main (int argc, char *argv[])
{
    char *msg;
    int done;

    /* Initialize SDL */
    if (SDL_Init (SDL_INIT_VIDEO) < 0)
    {
        sprintf (msg, "Couldn't initialize SDL: %s\n", SDL_GetError ());
        MessageBox (0, msg, "Error", MB_ICONHAND);
        free (msg);
        exit (1);
    }
    atexit (SDL_Quit);

    /* Set 640x480 16-bits video mode */
    screen = SDL_SetVideoMode (640, 480, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
    if (screen == NULL)
    {
        sprintf (msg, "Couldn't set 640x480x16 video mode: %s\n",
          SDL_GetError ());
        MessageBox (0, msg, "Error", MB_ICONHAND);
        free (msg);
        exit (2);
    }
    SDL_WM_SetCaption ("BIENVENDOS A INTERACTIVO COBAY", NULL);

    done = 0;
    while (!done)
    {
        SDL_Event event;

        /* Check for events */
        while (SDL_PollEvent (&event))
        {
            switch (event.type)
            {
            case SDL_KEYDOWN:
                break;
            case SDL_QUIT:
                done = 1;
                break;
            default:
                break;
            }
        }

        /* Draw to screen */
        draw ();
    }

    return 0;
}


Título: Re: SDL insertar imagenes [lenjuage C]
Publicado por: anonimo12121 en 8 Marzo 2011, 23:38 pm
Código:
SDL_Surface *imagen = SDL_LoadBMP("imagen.bmp"); //esto carga la imagen.

SDL_BlitSurface(imagen,0,PANTALLA,0);// en pantalla pones la SDL_Surface de la pantalla XDD. y los 0 es la posicion que copias de la //imagen , y la posicion donde la pegas en la pantalla poniendose "&" segudido de la variable SDL_RECT
//SDL_BlitSurface(imagen,&SDL_Rect,PANTALLA,&SDL_Rect);

PD:http://softwarelibre.uca.es/wikijuegos/Portada
PD2:  SDL_FillRect (screen, NULL, color); esto es para pintar.
PD3: Antes de correr empieza a caminar XDD suerte cualquier cosa intentare ayudarte
SALUDOS.


Título: Re: SDL insertar imagenes [lenjuage C]
Publicado por: JORGE BAAK en 9 Marzo 2011, 00:05 am
Código:
SDL_Surface *imagen = SDL_LoadBMP("imagen.bmp"); //esto carga la imagen.

SDL_BlitSurface(imagen,0,PANTALLA,0);// en pantalla pones la SDL_Surface de la pantalla XDD. y los 0 es la posicion que copias de la //imagen , y la posicion donde la pegas en la pantalla poniendose "&" segudido de la variable SDL_RECT
//SDL_BlitSurface(imagen,&SDL_Rect,PANTALLA,&SDL_Rect);

PD:http://softwarelibre.uca.es/wikijuegos/Portada
PD2:  SDL_FillRect (screen, NULL, color); esto es para pintar.
PD3: Antes de correr empieza a caminar XDD suerte cualquier cosa intentare ayudarte
SALUDOS.

hola amigo.. esos codigos que me pasaste van en?... en otro codigo o en el que postie? .. #noentender xD


Título: Re: SDL insertar imagenes [lenjuage C]
Publicado por: anonimo12121 en 9 Marzo 2011, 11:57 am
jaja XDD. ya te dicho tienes que leer XDD...

SDL_Surface sesto es una estructura. Pero podemos decir que son variables por ahora porque no le vas a dar un uso interno asi queson como tipos int char etc. pero en este caso SDL_Surface
SDL_Rect es otra estructura. que podríamos decir que son variables.
SDL_LoadBMP("imagen.bmp") es una funcion que devuelve un SDL_Surface.
SDL_Surface *scr= SDL_LoadBMP("imagen.bmp") ves aqui estas dando por decirlo de alguna manera un valor a esa variable.

SDL_BlitSurface(SDL_Surface origen,SDL_Rect origen, SDL_Surface destino, SDL_Rect destino) aqui se pondria las variables que ponen.
Y lo que hace es copiar el trozo de la variable que ha cargado una imagen al trozo del destino no sé si me explicado... por lo demás te recomiendo que leas el link que te pasé.