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
Zitat von »"alexm"«
für mich ist soweit mal klar, dass ich in der winMain die "spielschleife" brauche. bin nicht sicher ob ich das anhand des buches auf nicht-tribase umsetzen kann, aber ich denke dass das schon gehen wird.
Quellcode |
|
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 |
BOOL render() { D3DXMATRIXA16 matrix; this->m_pD3DDevice->SetTransform(D3DTS_WORLD, &matrix); this->m_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); // die inneren Seiten sind sichtbar this->m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE ); this->m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); // wenn keine textur gesetzt wurde, textur deaktivieren if (this->m_iIdOfTexture == -1) this->m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE); else // textur aktivieren g_cYukon3dTextureManager.setTextureByID(this->m_iIdOfTexture); // das viereck zusammenbauen, auf dem dann das bild platziert wird... // achtung der vertex muss folgend ausschauen: // xyz, normals, diffuse und tex1 ==> ist bei mir SVertex_Texture // also // D3DXVECTOR3, D3DXVECTOR3, float, float, float // du musst auch angeben, wie breit und wie hoch dein viereck sein soll: // m_fWidth , m_fHight, // m_fPos* gibt an, wo sich das viereck befinden soll. SVertex_Texture cvVertices[] = { // links oben {m_fPosX - (m_fWidth / 2), m_fPosY + (m_fHeight / 2), m_fPosZ, D3DCOLOR_XRGB(0, 0, 255), 0.0f, 0.0f,}, //Vertex 0 // links unten {m_fPosX - (m_fWidth / 2), m_fPosY - (m_fHeight / 2), m_fPosZ, D3DCOLOR_XRGB(255, 0, 0), 0.0f, 1.0f,}, //Vertex 1 // rechts oben {m_fPosX + (m_fWidth / 2), m_fPosY + (m_fHeight / 2), m_fPosZ, D3DCOLOR_XRGB(255, 0, 0), 1.0f, 0.0f,}, //Vertex 2 // rechts oben {m_fPosX + (m_fWidth / 2), m_fPosY + (m_fHeight / 2), m_fPosZ, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0.0f,}, //Vertex 3 // links unten {m_fPosX - (m_fWidth / 2), m_fPosY - (m_fHeight / 2), m_fPosZ, D3DCOLOR_XRGB(0, 0, 255), 0.0f, 1.0f,}, //Vertex 4 // rechts unten {m_fPosX + (m_fWidth / 2), m_fPosY - (m_fHeight / 2), m_fPosZ, D3DCOLOR_XRGB(255, 0, 0), 1.0f, 1.0f,}, //Vertex 5 }; LPDIRECT3DVERTEXBUFFER9 pVB = NULL; // Puffer für die Vertices SVertex_Texture* pVertexBufferStart; HRESULT hr; hr = this->m_pD3DDevice->SetFVF(D3DFVF_CUSTOMVERTEX_TEXTURE); hr = this->m_pD3DDevice->CreateVertexBuffer(6*sizeof(SVertex_Texture), // 6 vertices 0, D3DFVF_CUSTOMVERTEX_TEXTURE, D3DPOOL_MANAGED, &pVB, NULL); // den vertex puffer locken, damit man die daten hineinspielen kann. hr = pVB->Lock( 0, // start 6 * sizeof(SVertex_Texture), // speicherplatz der nötig ist (void **) &pVertexBufferStart, // pointer wo dann die daten liegen D3DLOCK_NOSYSLOCK ); memcpy(pVertexBufferStart, &cvVertices[0], 6 * sizeof(SVertex_Texture)); hr = pVB->Unlock(); // zeichnen hr = this->m_pD3DDevice->SetStreamSource(0, pVB, 0, sizeof(SVertex_Texture)); if (FAILED(this->m_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, // 2 Dreiecke cvVertices, // Vertices sizeof(SVertex_Texture)))) { SAFE_RELEASE(pVB); return FALSE; } SAFE_RELEASE(pVB); this->m_pD3DDevice->SetRenderState(D3DRS_CULLMODE, dwCullmode); // die inneren Seiten sind sichtbar this->m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, dwLighting ); this->m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, dwColorop); this->m_pD3DDevice->SetFVF(dwFVF); return TRUE; } void setTextureByID(int iID) { if(this->m_vbTextureTransparence[iID] == TRUE) { this->m_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); this->m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); this->m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); } HRESULT hr = this->m_pD3DDevice->SetTexture(0, prv_vecTexture[iID].pTexture); // <= hier wird die textur angegeben, die gezeichnet werden soll // bei mir ist alles in einem vektor... müsstest du an dein programm anpassen } // das laden einer textur int addTexture(const WTL::CString &strFile) { TexturePacket tempTexture; // Erstellt eine temporäre Instance tempTexture.strFile = strFile; //Der Dateiname wird übergeben if(FAILED(D3DXCreateTextureFromFile(this->m_pD3DDevice, strFile, &tempTexture.pTexture))) return -1; //Die Textur wird geladen, bei einem Fehler wird -1 zurück gegeben } |
Werbeanzeige