elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  SDL insertar imagenes [lenjuage C]
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: SDL insertar imagenes [lenjuage C]  (Leído 9,335 veces)
JORGE BAAK

Desconectado Desconectado

Mensajes: 18


Ver Perfil
SDL insertar imagenes [lenjuage C]
« 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;
}


En línea

anonimo12121


Desconectado Desconectado

Mensajes: 1.813


Ver Perfil WWW
Re: SDL insertar imagenes [lenjuage C]
« Respuesta #1 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.


« Última modificación: 8 Marzo 2011, 23:42 pm por Xafirot » En línea

Página para ganar Bitcoins y Dinero: http://earnbit.hol.es/
Video de YouTube con Hack para el LoL: http://adf.ly/5033746/youtube-lolemuhack
Si quieres ganar dinero con adfly entra y registrate aquí -> http://adf.ly/?id=5033746
JORGE BAAK

Desconectado Desconectado

Mensajes: 18


Ver Perfil
Re: SDL insertar imagenes [lenjuage C]
« Respuesta #2 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
En línea

anonimo12121


Desconectado Desconectado

Mensajes: 1.813


Ver Perfil WWW
Re: SDL insertar imagenes [lenjuage C]
« Respuesta #3 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é.
En línea

Página para ganar Bitcoins y Dinero: http://earnbit.hol.es/
Video de YouTube con Hack para el LoL: http://adf.ly/5033746/youtube-lolemuhack
Si quieres ganar dinero con adfly entra y registrate aquí -> http://adf.ly/?id=5033746
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Insertar imagenes en Inyección SQL « 1 2 »
Nivel Web
rikrdo_mat 12 8,876 Último mensaje 2 Diciembre 2010, 04:38 am
por 3st3
Insertar imágenes en C con Open GL
Programación C/C++
Markitukas 4 4,497 Último mensaje 6 Marzo 2012, 16:36 pm
por Markitukas
Getty Images libera 35 millones de imágenes, que cualquiera podrá insertar en...
Noticias
wolfbcn 0 1,245 Último mensaje 6 Marzo 2014, 12:47 pm
por wolfbcn
Insertar imágenes en el foro
Sugerencias y dudas sobre el Foro
anlimo69 2 3,131 Último mensaje 1 Septiembre 2015, 19:45 pm
por anlimo69
Aprovechan un bug de Facebook para insertar imágenes con las que infectarte ...
Noticias
wolfbcn 0 1,470 Último mensaje 25 Noviembre 2016, 21:42 pm
por wolfbcn
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines