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

21.02.2010, 15:34

Problem mit Textur

Hi

Ich bins schon wieder :D
Ich will mir eine Textur auf meinen Bildschirm werfen. Die Textur ist einfach erstmal nur Schwarz. Aber leidert erscheint keine Textur sondern nur die Farbe mit der der Backbuffer gecleart( :roll: ) wurde.

Color.h

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef COLOR_H
#define COLOR_H

#include <windows.h>

class Color
{
public:

    DWORD red;
    DWORD green;
    DWORD blue;

    Color();
};

#endif


Color.cpp

C-/C++-Quelltext

1
2
3
4
5
6
7
8
#include "Color.h"

Color::Color()
{
    red =   0x00ff0000;
    green = 0x0000ff00;
    blue =  0x000000ff;
}

Vektor3D.h(ohne operatoren)

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef VEKTOR3D_H
#define VEKTOR3D_H

class CUSTOMVERTEX
{
    public:
    float x,y,z;

    CUSTOMVERTEX(){}
    CUSTOMVERTEX(const CUSTOMVERTEX &customvertex) : x(customvertex.x),y(customvertex.y) {}
    CUSTOMVERTEX(float x,float y,float z) : x(x),y(y),z(z) {}
};



#endif


Vektor2D.h

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef VEKTOR2D_H
#define VEKTOR2D_H

class Vektor2D
{
    public:

    float x,y,z;

    Vektor2D(){}
    Vektor2D(const Vektor2D &vektor2D) : x(vektor2D.x),y(vektor2D.y) {}
    Vektor2D(float x,float y) : x(x),y(y) {}
};

#endif


Die VertexStruktur

C-/C++-Quelltext

1
2
3
4
5
6
7
8
struct STitleVertex
{
    CUSTOMVERTEX        vPosition;
    float               fRHW;
    D3DCOLOR            Color;
    Vektor2D            vTex0;
    static const DWORD  dwFVF;
};


Das VertexFormat

C-/C++-Quelltext

1
const DWORD STitleVertex::dwFVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1;


und jetzt das rendern des Hintergrundbildes

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
void SetBackgroundImage()
        {
            STitleVertex aVertex[4];

            id3d.pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, color.red, 1.0f, 0);
            id3d.pd3dDevice->BeginScene();

            id3d.pd3dDevice->SetFVF(STitleVertex::dwFVF);
            id3d.pd3dDevice->SetTexture(0, m_pTexture);
            id3d.pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);

            // Die vier Vertizes des Titelbilds erstellen (Rechteck)

            // Links unten

            aVertex[0].vPosition = CUSTOMVERTEX(0.0f, 0.0f, 0.5f);
            aVertex[0].fRHW = 1.0f;
            aVertex[0].Color = color.red;
            aVertex[0].vTex0 = Vektor2D(0.0f, 1.0f);

            // Links oben

            aVertex[1].vPosition = CUSTOMVERTEX(0.0f, 0.0f, 0.0f);
            aVertex[1].fRHW = 1.0f;
            aVertex[1].Color = color.red;
            aVertex[1].vTex0 = Vektor2D(0.0f, 0.0f);

            // Rechts unten

            aVertex[2].vPosition = CUSTOMVERTEX(0.0f, 0.0f, 0.5f);
            aVertex[2].fRHW = 1.0f;
            aVertex[2].Color = color.red;
            aVertex[2].vTex0 = Vektor2D(1.0f, 1.0f);

            // Rechts oben

            aVertex[3].vPosition = CUSTOMVERTEX(0.0f, 0.0f, 0.5f);
            aVertex[3].fRHW = 1.0f;
            aVertex[3].Color = color.red;
            aVertex[3].vTex0 = Vektor2D(1.0f, 0.0f);

            // Als Dreiecksfolge zeichnen

            id3d.pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, aVertex, sizeof(STitleVertex));
            id3d.pd3dDevice->EndScene();

        }
...
ir->SetBackgroundImage();
id3d.pd3dDevice->Present(NULL,NULL,NULL,NULL);


mit dem debugger bin ich schon durchgegangen und alles ist gültig, auch das Laden des Hintergrund bildes

Schon mal danke im voraus

Fabian
Metal ist keine Musik sondern eine Religion.

Databyte

Alter Hase

Beiträge: 1 040

Wohnort: Na zu Hause

Beruf: Student (KIT)

  • Private Nachricht senden

2

21.02.2010, 15:38

Hab gerade nur mal schnell rübergeguckt und die Farbe muss 32 Bit groß sein
Also ein DWORD und nicht 3... Fargbwerte gibts dann nur von 0 bis 255

GR-PA

Treue Seele

Beiträge: 326

Wohnort: Daheim

Beruf: Faulenzer

  • Private Nachricht senden

3

21.02.2010, 15:43

Dein "Rechteck" ist ja auch nur ein Pixel in der der linken oberen Ecke:

C-/C++-Quelltext

1
2
3
4
aVertex[0].vPosition = CUSTOMVERTEX(0.0f, 0.0f, 0.5f);// Position des Pixels oben links

aVertex[1].vPosition = CUSTOMVERTEX(0.0f, 0.0f, 0.0f);// Position des Pixels oben links

aVertex[2].vPosition = CUSTOMVERTEX(0.0f, 0.0f, 0.5f);// Position des Pixels oben links

aVertex[3].vPosition = CUSTOMVERTEX(0.0f, 0.0f, 0.5f);// Position des Pixels oben links
Signaturen werden überbewertet

idontknow

unregistriert

4

21.02.2010, 16:10

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Die vier Vertizes des Titelbilds erstellen (Rechteck)

            // Links unten

            aVertex[0].vPosition = CUSTOMVERTEX(0.0f, 0.0f, 0.5f);
            aVertex[0].vTex0 = Vektor2D(0.0f, 1.0f);

            // Links oben

            aVertex[1].vPosition = CUSTOMVERTEX(0.0f, 0.0f, 0.0f);
            aVertex[1].vTex0 = Vektor2D(0.0f, 0.0f);

            // Rechts unten

            aVertex[2].vPosition = CUSTOMVERTEX(1.0f, 0.0f, 0.5f);
            aVertex[2].vTex0 = Vektor2D(1.0f, 1.0f);

            // Rechts oben

            aVertex[3].vPosition = CUSTOMVERTEX(1.0f, 0.0f, 0.0f);
            aVertex[3].vTex0 = Vektor2D(1.0f, 0.0f);


Bin mal davon ausgegangen, dass dein Textur schon über X/Z gerendert werden soll, da du ja keine Y Werte verwendest bzw 0

5

21.02.2010, 18:14

Also, warum hat eigentlich Vector2D die elemente x, y und z ?

idontknow

unregistriert

6

21.02.2010, 18:26

Hat er doch nicht, das ist doch CUSTOMVERTEX..

7

21.02.2010, 19:51

aber in den Texturkoordinaten ;)

C-/C++-Quelltext

1
    Vektor2D            vTex0; 

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
class Vektor2D
{
    public:

    float x,y,z;

    Vektor2D(){}
    Vektor2D(const Vektor2D &vektor2D) : x(vektor2D.x),y(vektor2D.y) {}
    Vektor2D(float x,float y) : x(x),y(y) {}
}; 

8

21.02.2010, 20:19

oh mein Fehler :oops:

So sieht jetzt alles aus und es funktioniert trotzdem nicht :(

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
STitleVertex aVertex[4];

            id3d.pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET,0xFF00FF00, 1.0f, 0);
            id3d.pd3dDevice->BeginScene();

            id3d.pd3dDevice->SetFVF(STitleVertex::dwFVF);
            id3d.pd3dDevice->SetTexture(0, m_pTexture);
            id3d.pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);

            // Die vier Vertizes des Titelbilds erstellen (Rechteck)

            // Links unten

            aVertex[0].vPosition = CUSTOMVERTEX(0.0f, 0.0f, 0.5f);
            aVertex[0].fRHW = 1.0f;
            aVertex[0].color = Color(1.0f,0.0f,0.0f);
            aVertex[0].vTex0 = Vektor2D(0.0f, 1.0f);

            // Links oben

            aVertex[1].vPosition = CUSTOMVERTEX(0.0f, 0.0f, 0.0f);
            aVertex[1].fRHW = 1.0f;
            aVertex[1].color = Color(1.0f,0.0f,0.0f);
            aVertex[1].vTex0 = Vektor2D(0.0f, 0.0f);

            // Rechts unten

            aVertex[2].vPosition = CUSTOMVERTEX(1.0f, 0.0f, 0.5f);
            aVertex[2].fRHW = 1.0f;
            aVertex[2].color = Color(1.0f,0.0f,0.0f);
            aVertex[2].vTex0 = Vektor2D(1.0f, 1.0f);

            // Rechts oben

            aVertex[3].vPosition = CUSTOMVERTEX(1.0f, 0.0f, 0.0f);
            aVertex[3].fRHW = 1.0f;
            aVertex[3].color = Color(1.0f,0.0f,0.0f);
            aVertex[3].vTex0 = Vektor2D(1.0f, 0.0f);

            // Als Dreiecksfolge zeichnen

            id3d.pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, aVertex, sizeof(STitleVertex));
            id3d.pd3dDevice->EndScene();


C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef COLOR_H
#define COLOR_H

#include <windows.h>

class Color
{
public:
    float r,g,b,a;

    // Konstruktoren

    Color(){}
    Color(const Color& c) : r(c.r), g(c.g), b(c.b), a(c.a){}
    Color(const float f) : r(f), g(f), b(f), a(1.0f){}
    Color(const float _r, const float _g, const float _b) : r(_r), g(_g), b(_b), a(1.0f){}
};

#endif


ich habs so gemacht wie ihr vorgeschlagen hattet aber irgendwie gehts immer noch nicht
Metal ist keine Musik sondern eine Religion.

9

22.02.2010, 14:03

Sind die Positionen vllt immer noch nicht richtig?Ich mein so wie es jetzt ist müsste man doch mindestens die linke obere Ecke sehen oder?

PS:Ich hatte die Coordinaten aus dem Spiel Galactica genommen ;)
Metal ist keine Musik sondern eine Religion.

Databyte

Alter Hase

Beiträge: 1 040

Wohnort: Na zu Hause

Beruf: Student (KIT)

  • Private Nachricht senden

10

22.02.2010, 15:16

Deine Farbe muss aus einem DWORD bestehen ! dass sind 4 Byte.
Diese 4 Byte müssen jetzt die Farbwerte enthalten...
Die 4 Byte sind so aufgebaut:

alpha | rot | grün | blau

so kannst du das DWORD füllen:

C-/C++-Quelltext

1
2
3
4
#define ARGB(a,r,g,b) ((((BYTE)a) << 24) | (((BYTE)r) << 16) | (((BYTE)g) << 8) | (((BYTE)b))

// Das wäre Rot

DWORD color = ARGB(255, 255, 0, 0);



So ... dann ist der z-wert bei D3DFVF_XYZRHW erstmal egal, jedenfalls wenn du ZENABLE auf false setzt...
Dafür musst du andere y-werte angeben ( sonst is es nur ne horizontale linie )

Und versuch mal D3DRS_CULLMODE auf D3DCULL_NONE zu stellen ( bei mir lags mal daran... hab ewig gesucht ;) )

Werbeanzeige