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

24.09.2009, 18:08

kleines Syntaktisches Problem

hallo,

ich habe diese Struktur:

C-/C++-Quelltext

1
2
3
4
5
struct sTexture
{
    LPDIRECT3DTEXTURE9 texture;
    sTexture* next;
};


jetzt reserviere ich mir speicher auf dem heap per new sTexture; Jetzt habe ich einen Zeiger auf die Struktur, aber wie kann ich jetzt eine Textur rein laden? Sollte ungefähr so aussehen, nur dass der letzte parameter irgendwie anders aussehen muss:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
r = D3DXCreateTextureFromFileEx(    CDirect3D::lpD3DDevice,
                                            texturepath,
                                            ImgInfo.Width,
                                            ImgInfo.Height,
                                            1, 0,
                                            D3DFMT_UNKNOWN,
                                            D3DPOOL_MANAGED,
                                            D3DX_FILTER_NONE,
                                            D3DX_FILTER_NONE,
                                            0, 0, 0,
                                            &(newtexture->texture));

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

2

24.09.2009, 18:13

Was für ein Fehler bekommst du denn?

3

24.09.2009, 18:15

ich bekomme beim kompilieren überhaupt keinen fehler, aber die funktion schlägt einfach fehl, was aber nur am letzten parameter liegen kann.

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

4

24.09.2009, 18:16

Zitat von »"newby"«

ich bekomme beim kompilieren überhaupt keinen fehler, aber die funktion schlägt einfach fehl, was aber nur am letzten parameter liegen kann.


Dann ist es kein syntaktisches Problem... Und woher weißt du, das es nur am letzten parameter liegen kann?

5

24.09.2009, 18:18

weil genau die gleiche funktion mit den gleichen parameter funktioniert, wenn ich den letzten parameter ändere.
Das Problem ist insofern syntaktisch, dass ich nicht weiß wie die Syntax richtig lauten muss

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

6

24.09.2009, 18:24

Zitat von »"newby"«

weil genau die gleiche funktion mit den gleichen parameter funktioniert, wenn ich den letzten parameter ändere.
Das Problem ist insofern syntaktisch, dass ich nicht weiß wie die Syntax richtig lauten muss


Die Syntax ist korrekt, sonst würde der Compiler sich melden. Ansonsten kannst du ggf ein bisschen mehr relevanten Code posten, bzw wäre die "funktionierende" Variante auch ganz interessant.

7

24.09.2009, 18:29

die syntax ist korrekt, aber sie macht nicht das was ich will :?
funktionieren tut es so:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
r = D3DXCreateTextureFromFileEx(    CDirect3D::lpD3DDevice,
                                        texturepath,
                                        ImgInfo.Width,
                                        ImgInfo.Height,
                                        1, 0,
                                        D3DFMT_UNKNOWN,
                                        D3DPOOL_MANAGED,
                                        D3DX_FILTER_NONE,
                                        D3DX_FILTER_NONE,
                                        0, 0, 0,
                                        &texture);

wo bei texture ein private Member der klasse vom Typ LPDIRECT3DTEXTURE9 ist.

In der Klasse geht es um eine Animation, die man entweder aus einer Datei laden kann (das funktioniert) oder eben aus mehreren einzelen Bildern zusammensetzen. Bei letzterem möchte ich eine verkettete List der oben genannten Struktur erzeugen. Aber ich bekomme die Textur nicht geladen.

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

8

24.09.2009, 18:31

Mit so minimal wenig Code kann ich nur raten...

9

24.09.2009, 18:36

CAnimation.h

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
struct sTexture
{
    LPDIRECT3DTEXTURE9 texture;
    sTexture* next;
};

class DLL_EXPORT CAnimation : public CEngine
{
    public:

        void CreateSinglePictureAnimation(char* texturepath, int picturewidth, int picturecount, int pictureduration, bool independence, bool autoscale);
        void CreateMultiPictureAnimation(int pictureduration, bool independence, bool autoscale);
        void AddPicture(char* texturpath);
        void Show(int coordx, int coordy);
        void Start();
        void Stop();
        void Reset();
        void Scale(float factor);
        void SetScale(float factor);
        void Rotate(int angle);
        void SetRotation(int angle);

    private:

        LPDIRECT3DTEXTURE9 texture;
        sTexture* first;
        sTexture* last;

        int width;
        int height;
        int count;
        int duration;
        int lastchange;
        int position;

        float scalefactor;
        int rotationangle;

        bool independency;
        bool autoscaling;
        bool multipicture;
        bool running;
};


CAnimation.cpp

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
#include "Engine.h"

void CAnimation::CreateSinglePictureAnimation(char* texturepath, int picturewidth, int picturecount, int pictureduration, bool independence, bool autoscale)
{
    HRESULT r;

    D3DXIMAGE_INFO ImgInfo;
    r = D3DXGetImageInfoFromFile(texturepath, &ImgInfo);
    if(FAILED(r)) EngineLog.Log("Error in function D3DXGetImageInfoFromFile()", LOG_ERROR);

    width       = picturewidth;
    height      = ImgInfo.Height;
    count       = picturecount-1;
    duration    = pictureduration;
    lastchange  = 0;
    position    = 0;
    first       = NULL;
    last        = NULL;

    independency    = independence;
    autoscaling     = autoscale;
    multipicture    = false;
    running         = false;

    scalefactor     = 1.0f;
    rotationangle   = 0;

    r = D3DXCreateTextureFromFileEx(    CDirect3D::lpD3DDevice,
                                        texturepath,
                                        ImgInfo.Width,
                                        ImgInfo.Height,
                                        1, 0,
                                        D3DFMT_UNKNOWN,
                                        D3DPOOL_MANAGED,
                                        D3DX_FILTER_NONE,
                                        D3DX_FILTER_NONE,
                                        0, 0, 0,
                                        &texture);
    if(FAILED(r)) EngineLog.Log("Error in function D3DXCreateTextureFromFileEx()", LOG_ERROR);
}

void CAnimation::CreateMultiPictureAnimation(int pictureduration, bool independence, bool autoscale)
{
    width           = 0;
    height          = 0;
    count           = 0;
    duration        = pictureduration;
    lastchange      = 0;
    position        = 0;
    first           = NULL;
    last            = NULL;
    independency    = independence;
    autoscaling     = autoscale;
    multipicture    = true;
    running         = false;
    scalefactor     = 1.0f;
    rotationangle   = 0;
}

void CAnimation::AddPicture(char* texturepath)
{
    if(multipicture == true)
    {
        HRESULT r;

        D3DXIMAGE_INFO ImgInfo;
        r = D3DXGetImageInfoFromFile(texturepath, &ImgInfo);
        if(FAILED(r)) EngineLog.Log("Error in function D3DXGetImageInfoFromFile()", LOG_ERROR);

        count++;

        sTexture* newtexture = new sTexture;
        if(first == NULL) { first = newtexture; last = newtexture; }
        last->next = newtexture;
        newtexture->next = NULL;
        r = D3DXCreateTextureFromFileEx(    CDirect3D::lpD3DDevice,
                                            texturepath,
                                            ImgInfo.Width,
                                            ImgInfo.Height,
                                            1, 0,
                                            D3DFMT_UNKNOWN,
                                            D3DPOOL_MANAGED,
                                            D3DX_FILTER_NONE,
                                            D3DX_FILTER_NONE,
                                            0, 0, 0,
                                            &newtexture->texture);
        if(FAILED(r)) EngineLog.Log("Error in function D3DXCreateTextureFromFileEx()", LOG_ERROR);
    }
    else EngineLog.Log("You tried to add a new texture to a SinglePictureAnimation", LOG_WARNING);
}





void CAnimation::Show(int coordx, int coordy)
{
    HRESULT r;

    float x = static_cast<float>(coordx);
    float y = static_cast<float>(coordy);
    if(independency == true)
    {
        x = ResolutionWidth/OriginalResolutionWidth * x;
        y = ResolutionHeight/OriginalResolutionHeight * y;
    }

    float asfactorwidth     = 1.0f;
    float asfactorheight    = 1.0f;
    if(autoscaling == true)
    {
        asfactorwidth   = ResolutionWidth/OriginalResolutionWidth;
        asfactorheight  = ResolutionHeight/OriginalResolutionHeight;
    }

    D3DXVECTOR2 ScalingVector(asfactorwidth*scalefactor, asfactorheight*scalefactor);
    D3DXVECTOR2 CenterVector(static_cast<float>(width/2+x), static_cast<float>(height/2+y));
    float rotation = rotationangle*D3DX_PI/180;

    D3DXMATRIX matrix;
    D3DXMatrixTransformation2D( &matrix,
                                &CenterVector,
                                0.0f,
                                &ScalingVector,
                                &CenterVector,
                                rotation,
                                NULL);

    CDirect3D::lpSprite->SetTransform(&matrix);

    D3DXVECTOR3 PositionVector(x, y, 0.0f);
    D3DCOLOR ModulateColor = 0xFFFFFFFF;

    int time = timeGetTime();
    if(time - lastchange >= duration && running == true)
    {
        (position == count) ? position = 0 : position++;
        lastchange = time;
    }

    RECT rect;
    rect.left       = position*width;
    rect.top        = 0;
    rect.right      = (position+1)*width-1;
    rect.bottom = height;

    r = CDirect3D::lpSprite->Begin(D3DXSPRITE_ALPHABLEND);
    if(FAILED(r)) EngineLog.Log("Error in function lpSprite::Begin()", LOG_ERROR);

    r = CDirect3D::lpSprite->Draw(  texture,
                                    &rect,
                                    NULL,
                                    &PositionVector,
                                    ModulateColor);
    if(FAILED(r)) EngineLog.Log("Error in function lpSprite::Draw()", LOG_ERROR);

    r = CDirect3D::lpSprite->End();
    if(FAILED(r)) EngineLog.Log("Error in function lpSprite::End()", LOG_ERROR);

    D3DXMATRIX emptymatrix;
    r = CDirect3D::lpSprite->SetTransform(D3DXMatrixIdentity(&emptymatrix));
    if(FAILED(r)) EngineLog.Log("Error in function lpSprite::SetTransform()", LOG_ERROR);
}

void CAnimation::Scale(float factor)
{
    scalefactor *= factor;
}

void CAnimation::SetScale(float factor)
{
    scalefactor = factor;
}

void CAnimation::Rotate(int angle)
{
    rotationangle += angle;
}

void CAnimation::SetRotation(int angle)
{
    rotationangle = angle;
}

void CAnimation::Start()
{
    running = true;
}

void CAnimation::Stop()
{
    running = false;
}

void CAnimation::Reset()
{
    position = 0;
}

Lerikson

Alter Hase

Beiträge: 412

Wohnort: nördlich von Hamburg

Beruf: Schüler

  • Private Nachricht senden

10

24.09.2009, 18:37

bist du sicher das alle möglichen probleme mit der textur (falscher ordner, format,...etc.) ausgeschlossen sind?

Werbeanzeige