FAQ | Points | Add... | Recent posts | Search | Register | Log in


Dev-C++ SDL_Image Ładowanie pliku *.png


Post new topic  Reply to topic      Main Page -> Forum Index -> Programming Generally -> Beginners Programming -> Dev-C++ SDL_Image Ładowanie pliku *.png
Author
Message
cpprogramista
Poziom 7
Poziom 7


Joined: 12 Nov 2009
Posts: 24
Location: Luboń

Post#1 Post from the author of the topic 09 Mar 2010 17:15   

Dev-C++ SDL_Image *.png


Mam Poniższy program:
Code:
#include <windows.h>
#include "Plaplus.h"
#include <SDL.h>
#include <SDL_Image.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{

    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Plapluś",       /* Title Text */
           WS_POPUP | WS_MAXIMIZE, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           MaxX,
           MaxY,                /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}
/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Surface *IMG_Load(const char *file);
    SDL_Surface *paletka;
    SDL_Surface *pilka;
    BOOL klej=TRUE;
    PAINTSTRUCT ps;
    HDC hdc;
   
    switch (message)                  /*handle the messages */
    {
        case WM_CREATE:
            pilka=IMG_Load("pilka.png");
            paletka=IMG_Load("paletka.png");
            static HINSTANCE hInst = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
            //załaduj bitmapy do pamięci
            moja_bitmapa = LoadBitmap(hInst, "tlo1");
            moja_bitmapa1= LoadBitmap(hInst, "tlo2");
            //cegla_cz=LoadBitmap(hInst, "cegla_cz");
            if(!moja_bitmapa || !moja_bitmapa1 || !paletka || !pilka)
            {
                MessageBox(hwnd, "Błąd ładowania pliku!", "Błąd:",
                        MB_OK | MB_ICONEXCLAMATION);
                return -1;
            }
            //GetObject(cegla_cz, sizeof(bm4), &bm4);
            GetObject(moja_bitmapa, sizeof(bm), &bm);
            GetObject(paletka, sizeof(bm2), &bm2);
            GetObject(pilka, sizeof(bm3), &bm3);
            static int paletka_x=MaxX/2;
            static const int paletka_y=MaxY-25;
            static int pilka_x=paletka_x;
            static int pilka_y=paletka_y-((bm2.bmHeight/2)+(bm3.bmHeight/2)+9);
            break;
        case WM_PAINT:   
            hdc = BeginPaint(hwnd, &ps);
            Rysuj(hdc, paletka_x, paletka_y, pilka_x, pilka_y);
            EndPaint(hwnd, &ps);
            break;
        case WM_KEYDOWN:
            if(wParam==VK_LEFT)
            {
                if(paletka_x>bm2.bmWidth/2)
                {
                    paletka_x-=50;
                    if(klej==TRUE)
                    pilka_x-=50;
                }
            }
            if(wParam==VK_RIGHT)
            {
                if(paletka_x<MaxX-(bm2.bmWidth/2))
                {
                    paletka_x+=50;
                    if(klej==TRUE)
                    pilka_x+=50;
                }
            }
            if(wParam==VK_ESCAPE)
            {
                SendMessage(hwnd, WM_DESTROY, 0,0);
            }
            InvalidateRect(hwnd, NULL, TRUE);
            break;
        case WM_DESTROY:
            DeleteObject(moja_bitmapa);
            DeleteObject(pilka);
            DeleteObject(paletka);
            SDL_Quit();
            PostQuitMessage(0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

Kompilator zwraca mi błąd:
Code:
[Linker Error] undefined reference to `IMG_Load(char const*)'
ld returned 1 exit status
C:\Dev-Cpp\Kurs okienka\Tenis\Makefile.win [Build Error] exe: *** [Plapluś.exe] Error 1

Do wiersza poleceń konsolidatora dodałem:
Code:
-mwindows
../png/sdlDevCPP-1.2.4/lib/libSDL.a
../png/sdlDevCPP-1.2.4/lib/libSDLmain.a
-luser32
-lgdi32
-lwinmm
-ldxguid

Proszę o pomoc.
Back to top
   
Google

Google Adsense


Post# Post from the author of the topic 09 Mar 2010 17:15   





Back to top
   
arnoldziq
Poziom 23
Poziom 23


Joined: 14 Apr 2006
Posts: 2934
Location: High Wycombe

Post#2 09 Mar 2010 17:36   

Re: Dev-C++ SDL_Image Ładowanie pliku *.png


Na starcie usuń polskie znaki z nazwy projektu :
cpprogramista wrote:
Plapluś.exe

Back to top
   
cpprogramista
Poziom 7
Poziom 7


Joined: 12 Nov 2009
Posts: 24
Location: Luboń

Post#3 Post from the author of the topic 09 Mar 2010 17:53   

Re: Dev-C++ SDL_Image Ładowanie pliku *.png


bez SDL polskie znaki działają, a po usunięciu polskich znaków kompilator zwraca to samo
Back to top
   
Dr.Vee
Poziom 22
Poziom 22


Joined: 16 May 2008
Posts: 1808
Location: Wrocław

Post#4 10 Mar 2010 01:11   

Re: Dev-C++ SDL_Image Ładowanie pliku *.png


Najprawdopodobniej potrzebujesz dolinkować dodatkową bibliotekę: libSDL_image.a

Pozdrawiam,
Dr.Vee
Back to top
   
cpprogramista
Poziom 7
Poziom 7


Joined: 12 Nov 2009
Posts: 24
Location: Luboń

Post#5 Post from the author of the topic 10 Mar 2010 14:45   

Re: Dev-C++ SDL_Image Ładowanie pliku *.png


Skąd ją pobiorę? Szukałem jej i nie mogę znaleźć.
Back to top
   
Google

Google Adsense


Post# Post from the author of the topic 10 Mar 2010 14:45   





Back to top
   
edd123
Poziom 5
Poziom 5


Joined: 06 Jan 2010
Posts: 11

Post#6 13 Mar 2010 15:20   

Re: Dev-C++ SDL_Image Ładowanie pliku *.png


Co prawda nie używałem SDLa w WinApi ale zdaje mi się że brakuje tu "IMG_INIT_PNG". Ponadto gdy odwoływałem się do Surface'a do którego wczytałem plik instrukcją IMG_Load to też wywalało błąd. Wtedy robiłem tak:

Code:
SDL_Surface *wczytaj;
SDL_Surface *obrazek;
wczytaj = IMG_Load("obrzek.png");
obrazek = SDL_DisplayFormat(wczytaj);
SDL_FreeSurface(wczytaj);


I wszystko działało.
Back to top
   
cpprogramista
Poziom 7
Poziom 7


Joined: 12 Nov 2009
Posts: 24
Location: Luboń

Post#7 Post from the author of the topic 13 Mar 2010 15:28   

Re: Dev-C++ SDL_Image Ładowanie pliku *.png


Teraz kompilator zwraca
Code:
`IMG_INIT_PNG' was not declared in this scope

Back to top
   
edd123
Poziom 5
Poziom 5


Joined: 06 Jan 2010
Posts: 11

Post#8 13 Mar 2010 15:32   

Re: Dev-C++ SDL_Image Ładowanie pliku *.png


Zapomniałem dopisać że do działania potrzebny mi był plik "libpng12-0.dll". Albo spróbuj zapisać samo IMG_INIT. No i na końcu dodaj instrukcję IMG_Quit()
Back to top
   
Google

Google Adsense


Post# 13 Mar 2010 15:32   





Back to top
   
cpprogramista
Poziom 7
Poziom 7


Joined: 12 Nov 2009
Posts: 24
Location: Luboń

Post#9 Post from the author of the topic 13 Mar 2010 18:41   

Re: Dev-C++ SDL_Image Ładowanie pliku *.png


Teraz mam
Code:
IMG_INIT was not declared in this scope
IMG_Quit() was not declared in this scope

Back to top
   
edd123
Poziom 5
Poziom 5


Joined: 06 Jan 2010
Posts: 11

Post#10 13 Mar 2010 19:20   

Re: Dev-C++ SDL_Image Ładowanie pliku *.png


To jedynym sensownym wytłumaczeniem jest brak jakiegoś pliku, o czym wcześniej już ktoś pisał.
Back to top
   
cpprogramista
Poziom 7
Poziom 7


Joined: 12 Nov 2009
Posts: 24
Location: Luboń

Post#11 Post from the author of the topic 13 Mar 2010 19:28   

Re: Dev-C++ SDL_Image Ładowanie pliku *.png


OK. Znalazłem libSDL_Image.a i dołączyłem. Teraz mam:
Code:
#include <windows.h>
#include "Plaplus.h"
#include <SDL.h>
#include <SDL_Image.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{

    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Plapluś",       /* Title Text */
           WS_POPUP | WS_MAXIMIZE, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           MaxX,
           MaxY,                /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}
/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Surface *wczytaj;
    SDL_Surface *paletka;
    wczytaj = IMG_Load("Paletka.png");
    paletka = SDL_DisplayFormat(wczytaj);
    SDL_Surface *pilka;
    BOOL klej=TRUE;
    PAINTSTRUCT ps;
    HDC hdc;
    char pilka1[]="piłka.png", paletka1[]="paletka.png";
   
    switch (message)                  /*handle the messages */
    {
        case WM_CREATE:
            pilka=IMG_Load(pilka1);
            static HINSTANCE hInst = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
            //załaduj bitmapy do pamięci
            moja_bitmapa = LoadBitmap(hInst, "tlo1");
            moja_bitmapa1= LoadBitmap(hInst, "tlo2");
            cegla_cz=LoadBitmap(hInst, "cegla_cz");
            if(!moja_bitmapa || !moja_bitmapa1 || !paletka || !pilka)
            {
                MessageBox(hwnd, "Błąd ładowania pliku!", "Błąd:",
                        MB_OK | MB_ICONEXCLAMATION);
                return -1;
            }
            GetObject(cegla_cz, sizeof(bm4), &bm4);
            GetObject(moja_bitmapa, sizeof(bm), &bm);
            GetObject(paletka, sizeof(bm2), &bm2);
            GetObject(pilka, sizeof(bm3), &bm3);
            static int paletka_x=MaxX/2;
            static const int paletka_y=MaxY-25;
            static int pilka_x=paletka_x;
            static int pilka_y=paletka_y-((bm2.bmHeight/2)+(bm3.bmHeight/2)+9);
            break;
        case WM_PAINT:   
            hdc = BeginPaint(hwnd, &ps);
            Rysuj(hdc, paletka_x, paletka_y, pilka_x, pilka_y);
            SDL_FreeSurface(wczytaj);
            EndPaint(hwnd, &ps);
            break;
        case WM_KEYDOWN:
            if(wParam==VK_LEFT)
            {
                if(paletka_x>bm2.bmWidth/2)
                {
                    paletka_x-=50;
                    if(klej==TRUE)
                    pilka_x-=50;
                }
            }
            if(wParam==VK_RIGHT)
            {
                if(paletka_x<MaxX-(bm2.bmWidth/2))
                {
                    paletka_x+=50;
                    if(klej==TRUE)
                    pilka_x+=50;
                }
            }
            if(wParam==VK_ESCAPE)
            {
                SendMessage(hwnd, WM_DESTROY, 0,0);
            }
            InvalidateRect(hwnd, NULL, TRUE);
            break;
        case WM_DESTROY:
            DeleteObject(moja_bitmapa);
            DeleteObject(pilka);
            DeleteObject(paletka);
            SDL_Quit();
            PostQuitMessage(0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

oraz:
Code:
const int MaxX=GetSystemMetrics(SM_CXSCREEN);
const int MaxY=GetSystemMetrics(SM_CYSCREEN);
HBITMAP moja_bitmapa, moja_bitmapa1, paletka, pilka, cegla_cz;
BITMAP bm, bm2, bm3, bm4, bm5, bm6, bm7, bm8, bm9;

void Rysuj(HDC hdc, int paletka_x, int paletka_y, int pilka_x, int pilka_y)
{
    HDC hdc_bitmapy, hdc_bitmapy1, hdc_paletki, hdc_bitmapy3, hdc_bitmapy4, hdc_cegielek, hdc_pilki;     
    hdc_bitmapy=CreateCompatibleDC(hdc);
    hdc_paletki=CreateCompatibleDC(hdc);
    hdc_pilki=CreateCompatibleDC(hdc);
    hdc_cegielek=CreateCompatibleDC(hdc);
    SelectObject(hdc_bitmapy, moja_bitmapa);
    StretchBlt(hdc, 0, 0, MaxX, MaxY, hdc_bitmapy, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
    SelectObject(hdc_paletki, paletka);
    StretchBlt(hdc, paletka_x-(411/2), paletka_y-(52/2), 411, 52, hdc_paletki, 0, 0, bm2.bmWidth, bm2.bmHeight, SRCCOPY);
    SelectObject(hdc_pilki, pilka);
    StretchBlt(hdc, pilka_x-25, pilka_y-25, 50, 50, hdc_pilki, 0, 0, bm3.bmWidth, bm3.bmHeight, SRCCOPY);
    DeleteDC(hdc_bitmapy);
    DeleteDC(hdc_paletki);
    DeleteDC(hdc_pilki);
    DeleteDC(hdc_cegielek);
}
i:
Code:
tlo1  BITMAP "Plaża.bmp"
tlo2  BITMAP "Las.bmp"
tlo3  BITMAP "Piaskownica.bmp"
tlo4  BITMAP "Ogród.bmp"
cegla_cz BITMAP "Cegła_czerwona.bmp"
A kompilator zwraca
Code:
C:\Dev-Cpp\Kurs okienka\Tenis\Makefile.win [Build Error] exe: *** [Plaplus.exe] Error 1

Back to top
   
Post new topic  Reply to topic      Main Page -> Forum Index -> Programming Generally -> Beginners Programming -> Dev-C++ SDL_Image Ładowanie pliku *.png
Page 1 of 1
Similar topics
Rzeczywisty obraz płytki w PNG (5)
png a przeglądarka IE (html,js) (5)
[VB] Ładowanie do pictureboxa i usuwanie pliku z dysku. (1)
[VB 2008.NET] Plik PNG kanał alpha, cień. (3)
PCB w formacie .png jak i czym edytować ? (5)
Schemat układu *png do eagla, altiuma (5)
[Dev C++] Nie można uruchomić pliku exe. (8)
Język C a C++, Dev-C++, nie uruchamia pliku, program w C. (9)
wczytanie pliku o rozsz. cvs c++ w dev c++ (3)
Dev C++ tworzenie pliku HEX (6)

Page generation time: 0.141 seconds


FAQ || Administrator || Moderators || Widgets and banners || Contact
elektroda.pl topic RSS feed