Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

12.03.2007, 19:49

Hintergrund von Sprite

Ich arbeite gerade an einem Spiel und habe da folgende Frage:
Ich will ein Sprite vor den Hintergrund laden, aber der Rahmen des Sprite wird weiterhin angezeigt, obwohl ich die Farbe transparent geschaltet habe. Kann mir jemand helfen? Hier ist der Code:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <d3dx9.h>
#include <d3d9.h>

HWND CreateMainWindow(HINSTANCE hInstance);

LRESULT CALLBACK MessageHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

BOOL InitDirect3D(HWND hWnd);

float xpos = 30.0f;

float ypos = 440.0f;

LPDIRECT3DSURFACE9 background = NULL;

LPDIRECT3DSURFACE9 backbuffer = NULL;

LPD3DXSPRITE sprite = NULL;

LPDIRECT3DTEXTURE9 player_tex = NULL;

LPDIRECT3D9       lpD3D       = NULL;

LPDIRECT3DDEVICE9 lpD3DDevice = NULL;

void CleanUpDirect3D(void);

HWND hWnd = 0;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                                        LPSTR lpCmdLine,
                                        int nCmdShow)
{
    hWnd = CreateMainWindow(hInstance);

    if(0==hWnd)
    {
        MessageBox(0,"Fenster konnte nicht erzeugt werden!","Fehler",MB_OK);
        return -1;
    }

    if(!(InitDirect3D(hWnd)))
    {
        MessageBox(0,"DirectX konnte nicht initialisiert werden!","Fehler",MB_OK);
        return -1;
    }

    MSG msg;

    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    CleanUpDirect3D();

    return 0;
}

HWND CreateMainWindow(HINSTANCE hInstance)
{
    WNDCLASSEX wndClass = {
        sizeof(WNDCLASSEX),
        CS_DBLCLKS | CS_OWNDC |
        CS_HREDRAW | CS_VREDRAW,
        MessageHandler,
        0,
        0,
        hInstance,
        LoadIcon(NULL, IDI_WINLOGO),
        LoadCursor(NULL, IDC_ARROW),
        (HBRUSH)GetStockObject(WHITE_BRUSH),
        NULL,
        "WindowClass",
         LoadIcon(NULL, IDI_WINLOGO)
    };
    RegisterClassEx(&wndClass);
    return CreateWindowEx(
                           NULL,
                           "WindowClass",
                           "Leeres Fenster",
                           WS_OVERLAPPEDWINDOW |
                           WS_VISIBLE,
                           0,0,
                           800,600,
                           NULL,
                           NULL,
                           hInstance,
                           NULL);
}

LRESULT CALLBACK MessageHandler(HWND hWnd, UINT msg, WPARAM wParam,
                                                     LPARAM lParam)
{
    D3DCOLOR ClearColor =D3DCOLOR_XRGB(0,0,0);
    switch(msg)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
        case WM_KEYDOWN:
            switch(wParam)
            {
            case VK_RIGHT:
                xpos +=10;
            break;
            case VK_LEFT:
                xpos -=10;
            break;
            case VK_UP:
                ypos -= 10;
            break;
            case VK_DOWN:
                ypos += 10;
            break;
            case VK_ESCAPE:
                PostQuitMessage(0);
            break;
            }
        break;
        case WM_RBUTTONDOWN:
            InvalidateRect(hWnd,0,TRUE);
            break;
        case WM_PAINT:
            D3DXCreateTextureFromFileEx( //Textur laden

                lpD3DDevice, 
                "player.bmp",
                60,
                120,
                1,
                0,
                D3DFMT_UNKNOWN,
                D3DPOOL_MANAGED,
                D3DX_FILTER_NONE,
                D3DX_FILTER_NONE,
                D3DCOLOR_ARGB(255,0,0,0),
                NULL,
                0,
                &player_tex);
            lpD3DDevice -> Clear(0,0,D3DCLEAR_TARGET, ClearColor,0,0);
            RECT r = {0,0,1024,768};
            lpD3DDevice -> BeginScene();
            lpD3DDevice->StretchRect(background,NULL,backbuffer,&r, D3DTEXF_NONE);
            sprite->Begin(D3DXSPRITE_SORT_DEPTH_FRONTTOBACK);
            D3DXVECTOR3 pcenter(30.0f,60.0f,0.0f);
            D3DXVECTOR3 pposition(xpos,ypos,1.0f);
            D3DCOLOR modulate = D3DCOLOR_ARGB(0,255,255,255);
            sprite->Draw(player_tex,NULL,&pcenter,&pposition,modulate); //Sprite anzeigen

            sprite->End();
            lpD3DDevice -> EndScene();
            lpD3DDevice -> Present(0,0,0,0);
            return 0;
        break;
    }
    return (DefWindowProc(hWnd, msg,wParam,lParam));
}

BOOL InitDirect3D(HWND hWnd)
{
    lpD3D = Direct3DCreate9(D3D_SDK_VERSION);
    if(NULL == lpD3D)
    {
        return FALSE;
    }

    D3DPRESENT_PARAMETERS PParams;
    ZeroMemory(&PParams, sizeof(PParams));
    PParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
    PParams.hDeviceWindow = hWnd;
    PParams.Windowed = FALSE;
    PParams.BackBufferWidth = 1024;
    PParams.BackBufferHeight =768;
    PParams.BackBufferFormat =D3DFMT_A8R8G8B8;
    if(FAILED(lpD3D->CreateDevice(
                    D3DADAPTER_DEFAULT,
                    D3DDEVTYPE_HAL,
                    hWnd,
                    D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                    &PParams,
                    &lpD3DDevice)))
    {
        return FALSE;
    }
    RECT sr = {0,0,1024,768};
    lpD3DDevice->CreateOffscreenPlainSurface(1024,768,D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &background, NULL); 
    lpD3DDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer); 
    D3DXLoadSurfaceFromFile(background,NULL, NULL, "background.jpg", NULL, D3DX_DEFAULT, 0, NULL); 
    D3DXCreateSprite(lpD3DDevice, &sprite); //Spriteobjekt erstellen

    return TRUE;
}

void CleanUpDirect3D(void)
{
    if(NULL !=lpD3DDevice)
    {
        lpD3DDevice -> Release();
        lpD3D =NULL;
    }
    if(NULL !=lpD3D)
    {
        lpD3D -> Release();
        lpD3D = NULL;
    }
}

2

12.03.2007, 20:24

Ich habe es jetzt geschafft es transparent zu stellen, die Figur ist aber leider jetzt schwarz^^ weiß jemand rat??

3

14.03.2007, 14:11

...in C# muß man eine Variable

C-/C++-Quelltext

1
device.RenderState.Enlighted = true;//nicht nur die Farben der Dreiecke sondern auch die Lichteinstellungen berücksichtigen


setzen sowie

C-/C++-Quelltext

1
device.Light[0].Enabled = true;//Lichtquelle einschalten


Keine Ahnung, ob Dir das weiterhilft.... :?:

4

14.03.2007, 17:27

leider nicht viel ich arbeite mit C++^^

Bösewicht

unregistriert

5

14.03.2007, 17:29

Muss man angeben :) aber hast du das Problem eigentlich schon gelöst?

Werbeanzeige