D3D7 Texturing woes

Started by
13 comments, last by Kylotan 21 years, 3 months ago
Rewrite your color op to this:

D3DTSS_COLORARG1, D3DTA_TEXTURE
D3DTSS_COLOROP, D3DTOP_SELECTARG1

leave out COLORARG2.

Look thru renderstate flags in the docs if there is something about setting a special state when doing vertex alpha, etc. If there is an error the debug runtime will let you know. This bug is probably logical error in your app, like setting flags and so on. I used nvidia''s 12.41 driver for year and a half and no problems. I just switched to 41.09 drv. and again no problems. I guess I''ve been lucky picking correct drivers Try them both however this blending op is so basic that I doubt drivers are buggy. I would still create a small dx7 test app just to make sure the rendering logic and flag are set correctly then when the test app passes, compare it to the rendering code in your normal app.

Advertisement
Ignore the rewrite part. Just looked into docs and D3DTA_CURRENT defaults to DIFFUSE. I thought you made a mistake but you didn''t. Sorry.
I see you''re using triangle strip as a draw primitive. If your tiles are quads and have four vertices going in cc/ccw order ie. one after another, then strip will not render properly. I just tried it. I use triangle fan for non-indexed four vertices ie. 2 triangles. Also, some time ago I derived MYCUSTOMVERTEX from d3dx vector3 class and I''ve mistakingly made my derived class virtual. That has put an extra 4 bytes for the virtual table pointer into my class. Suffice to say my app didn''t render properly because I omitted this 4 bytes from my vertex stride calculation. Posting your complete drawing/init/texture loading/etc. code would help tremendously to figure out what you''re doing.

  ----------Surface Creation--------------	DDSURFACEDESC2 ddsd;DXInitStruct(ddsd); // this is the memset/size thingddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_WRITEONLY;ddsd.ddsCaps.dwCaps2 = DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_OPAQUE; ddsd.ddsCaps.dwCaps3 = 0;ddsd.ddsCaps.dwCaps4 = 0;ddsd.dwHeight = y; ddsd.dwWidth = x;memcpy(&ddsd.ddpfPixelFormat, &textureFormats[chosenTexFormatIndex], sizeof(DDPIXELFORMAT));IDirectDrawSurface7* surfaceData = 0;if (HRESULT res = directDraw->CreateSurface(&ddsd, &surfaceData, NULL)){    logFile << "Failed to create DDraw surface:" << GetDXReturnCode(res) << endl;    return 0;}---------Rendering each tile--------------// Positions (vectors) firstconst float LEFT = static_cast<float>(dest.x);const float RIGHT = static_cast<float>(dest.x + dest.w);const float TOP = static_cast<float>(dest.y);const float BOTTOM = static_cast<float>(dest.y + dest.h);const float Z_VAL = 0.1f;const D3DVECTOR tl(LEFT, TOP, Z_VAL);const D3DVECTOR tr(RIGHT, TOP, Z_VAL);const D3DVECTOR bl(LEFT, BOTTOM, Z_VAL);const D3DVECTOR br(RIGHT, BOTTOM, Z_VAL);// Then actual verticesopacity = 1.0;const D3DCOLOR col = D3DRGBA(1.0, 1.0, 1.0, opacity);D3DTLVERTEX spriteVert[4];// Cast from Sprite to D3D7_Spriteconst D3D7_Sprite* d3dSprite = static_cast<const D3D7_Sprite*>(sprite); spriteVert[0] = D3DTLVERTEX(tl, 1, col, col, d3dSprite->u1, d3dSprite->v1); // TLspriteVert[1] = D3DTLVERTEX(tr, 1, col, col, d3dSprite->u2, d3dSprite->v1); // TRspriteVert[2] = D3DTLVERTEX(bl, 1, col, col, d3dSprite->u1, d3dSprite->v2); // BLspriteVert[3] = D3DTLVERTEX(br, 1, col, col, d3dSprite->u2, d3dSprite->v2); // BRHRESULT hr;// makes no differencedevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT/*D3DTA_DIFFUSE*/);// Allow vertex alpha, and texture alphadevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);#ifdef DEBUGDWORD passes = -10;hr = device->ValidateDevice(&passes);Log::Get() << "ValidateDevice: " << GetDXReturnCode(hr) << ", passes: " << passes << endl;#endif // DEBUG// Set the appropriate texture// Cast from Surface to D3D7_SurfaceD3D7_Surface* d3dSurface = static_cast<D3D7_Surface*>(d3dSprite->surface);if (!d3dSurface){#ifdef DEBUG    Log::Get() << "D3D7_Graphics::Render: d3dSurface is NULL!" << endl;#endif // DEBUG    return false;}// This gets the IDirectDrawSurface7* from the D3D7_Surface objectif (FAILED(hr = d3dSurface->GetDDSurface()->IsLost())){#ifdef DEBUG    Log::Get() << "D3D7_Graphics::Render: surface->IsLost(): " << GetDXReturnCode(hr) << endl;#endif // DEBUG    return false;}// Use that as the textureif (FAILED(hr = device->SetTexture(0, d3dSurface->GetDDSurface()))){#ifdef DEBUG    Log::Get() << "D3D7_Graphics::Render: SetTexture: " << GetDXReturnCode(hr) << endl;#endif // DEBUG    return false;}// Draw the object using a DrawPrimitive() call.if (FAILED(hr = device->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX,						   (void*)&spriteVert[0], 4, NULL))){#ifdef DEBUG    Log::Get() << "D3D7_Graphics::Render: DrawPrimitive: " << GetDXReturnCode(hr) << endl;#endif // DEBUG    return false;}  


That''s my drawing and surface creation code. Will post the init code too if the above checks out ok.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
I''ve looked at the code but haven''t found anything out of the ordinary. In case you''re letting d3d do the lighting for you the docs recommend to use color vertex and material source renderstate flags to tell the api to take color+alpha from vertices not material. You can post the rest of code and I''ll take a look at it. I can''t compile it though because I''m on dx9 but I have dx7 docs that I use to look up stuff.

P.S. Are you setting dwSize member in DXInitStruct(ddsd)? Your comments indicate you are but I want to make sure.

This topic is closed to new replies.

Advertisement