Archived

This topic is now archived and is closed to further replies.

More Textured Quad Problems!!?!?!

This topic is 5124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, so i followed this sites tutorial on creating textured quads, but they wont render, do i hafta do anything to my WNDCLASSEX? should i use the windows hWnd with the Present? what do i do? oh, and you could tell me HOW to post code if yah want me to, cuz i have no clue [edited by - Ademan555 on December 1, 2003 2:03:20 AM]

Share this post


Link to post
Share on other sites
your description is so very vague, code really is the way to go, type the word "source" in square brackets before and efter your chunck. THis is mis-spelled on purpose or else you wouldn;t see it:

[souurce]

past code here...

[/souurce]

Share this post


Link to post
Share on other sites
K heres my WndMain...
to tell yah the truth ive never started up d3d in fullscreen b4, my book never fully explains it :-/


//PREPROCESSOR

//INCLUDES

#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include "ClassHead.h"
//END INCLUDES


//DEFINES

#define DANSTYLE CS_HREDRAW|CS_VREDRAW|CS_OWNDC
#define GAMENAME "Dan's Game Engine v.01"
#define WIN32_LEAN_AND_MEAN
//END DEFINES

//END PREPROCESSOR


//GLOBALS

//VARIABLES

CAMERA Camera;
//END VARIABLES

//FUNCTIONS

long CALLBACK MainWndHndlr(HWND, UINT, WPARAM, LPARAM); HRESULT Shutdown(HINSTANCE, LPDIRECT3D9*, LPDIRECT3DDEVICE9*);
HRESULT InitD3D(HWND, LPDIRECT3D9*, LPDIRECT3DDEVICE9*);
HRESULT InitGame();
//END FUNCTIONS

//END GLOBALS

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR CmdLine, int iCmdShow)
{
//LOCALS

//VARIABLES

WNDCLASSEX MainWnd;
HWND hWnd;
LPDIRECT3D9 D3D=NULL;
LPDIRECT3DDEVICE9 D3DDev=NULL;
MSG Message;
ENTITY* Temp;
//DEBUG

BACKGROUNDIMAGE Bk;
Bk.Load("C:\\DEBUG\\Background.bmp", &D3DDev);
OutputDebugString("Background Loaded\n");
VISIBLEOBJ Obj;
Obj.LoadSprite("C:\\DEBUG\\Shit.bmp", &D3DDev);
OutputDebugString("Sprite Loaded\n");
//END DEBUG

//END VARIABLES

//END LOCALS


//WNDCLASSEX FILLING

MainWnd.cbClsExtra=0;
MainWnd.cbSize=sizeof(WNDCLASSEX);
MainWnd.cbWndExtra=0;
MainWnd.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
MainWnd.hCursor=NULL;
MainWnd.hIcon=LoadIcon(NULL, IDI_APPLICATION);
MainWnd.hIconSm=MainWnd.hIcon;
MainWnd.hInstance=hInstance;
MainWnd.lpfnWndProc=MainWndHndlr;
MainWnd.lpszClassName="MainWnd";
MainWnd.lpszMenuName=NULL;
MainWnd.style=DANSTYLE;
//END WNDCLASSEX FILLING

OutputDebugString("Windows Class Created\n");
//WNDCLASSEX

RegisterClassEx(&MainWnd);
hWnd=CreateWindowEx(WS_EX_TOPMOST, "MainWnd", GAMENAME, WS_POPUP|WS_SYSMENU|WS_VISIBLE, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);
OutputDebugString("Window Created\n");
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);
//END WNDCLASSEX

//INITIALIZATION

D3D = Direct3DCreate9(D3D_SDK_VERSION);
if (D3D==NULL)return 0;
if (FAILED(InitD3D(hWnd, &D3D, &D3DDev)))
{
OutputDebugString("Failed to initialize D3D\n");
Shutdown(hInstance, &D3D, &D3DDev);
return 0;
}
OutputDebugString("D3D Created Successfully\nEntering Loop\n");
while (1)
{
if (PeekMessage(&Message, hWnd, 0, 0, PM_REMOVE))
{
if (Message.message==WM_QUIT)
{
Shutdown(hInstance, &D3D, &D3DDev);
return 0;
}
}
else
{
if (GetAsyncKeyState(VK_ESCAPE))
{
OutputDebugString("Escape Key Pressed\n");
Shutdown(hInstance, &D3D, &D3DDev);
return 0;
}
//DEBUG

Bk.Render(&D3DDev);
Obj.Render(&D3DDev, 0);
//END DEBUG

D3DDev->EndScene();
D3DDev->Present(NULL, NULL, NULL, NULL);
}
}
Shutdown(hInstance, &D3D, &D3DDev);
return 0;
}

long CALLBACK MainWndHndlr(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
switch(uMessage)
{
case WM_CREATE:
return 0;
case WM_PAINT:
ValidateRect(hWnd, NULL);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
default:
return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
}

HRESULT Shutdown(HINSTANCE hInstance, LPDIRECT3D9* pD3D, LPDIRECT3DDEVICE9* ppD3DDev)
{
UnregisterClass("MainWnd", hInstance);
if(*ppD3DDev)(*ppD3DDev)->Release();
if(*pD3D)(*pD3D)->Release();
return S_OK;
}

HRESULT InitD3D(HWND hWnd, LPDIRECT3D9* pD3D, LPDIRECT3DDEVICE9* ppDev)
{
//LOCALS

//VARIABLES

D3DPRESENT_PARAMETERS d3dpp;
D3DDISPLAYMODE d3ddm;
//END VARIABLES

//END LOCALS


if (*ppDev)(*ppDev)->Release();

ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
if (FAILED((*pD3D)->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))return E_FAIL;

d3dpp.BackBufferWidth=640;
d3dpp.BackBufferHeight=480;
d3dpp.BackBufferFormat=D3DFMT_X8R8G8B8;
d3dpp.BackBufferCount=1;
d3dpp.MultiSampleType=D3DMULTISAMPLE_NONE;
d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow=hWnd;
d3dpp.Windowed=FALSE;
d3dpp.EnableAutoDepthStencil=TRUE;
d3dpp.AutoDepthStencilFormat=D3DFMT_D16;
d3dpp.FullScreen_RefreshRateInHz=0;
d3dpp.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.Flags=D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;

if (FAILED((*pD3D)->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, ppDev)))return E_FAIL;
(*ppDev)->SetVertexShader(NULL);
(*ppDev)->SetFVF(D3DFVF_TXVERTEX);

(*ppDev)->SetRenderState(D3DRS_LIGHTING, FALSE);
(*ppDev)->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
(*ppDev)->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
(*ppDev)->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
(*ppDev)->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);

return S_OK;
}



Just a side note, not a single debug string ever printed...



[edited by - Ademan555 on December 1, 2003 10:30:02 AM]

Share this post


Link to post
Share on other sites
I don''t know what types BACKGROUNDIMAGE and VISIBLEOBJ are, so I have no idea what happens when you call their render method.

However, I don''t see a call to BeginScene anywhere, nor a call to Clear, so that could definitely be your problem.

What book are you reading? If it doesn''t explain these simple things, than I''d recommend recycling it. I''d recommend that you check out the tutorials on my site. Completely free, and they should get you sorted out. They also cover setting up the Debug runtime, which if it was set up you''d know what was wrong ''cuz it''d be complaining bitterly about BeginScene not being called.

Tutorials:
www.drunkenhyena.com (or just click my sig)


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
alright thanx :-D

Im about to go to school...
but heres my "sprite" header file

(the renders of visibleobj and background image both just make calls to the render of this)


//PREPROCESSOR

//DEFINES

#define D3DFVF_TXVERTEX D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1
#define VT_UP_LEFT 0
#define VT_UP_RIGHT 1
#define VT_LO_LEFT 2
#define VT_LO_RIGHT 3
//END DEFINES

//END PREPROCESSOR


//FUNCTION LIST

HRESULT LoadBitmapToSurface(char*, LPDIRECT3DSURFACE9*, LPDIRECT3DDEVICE9, int*, int*);
//END FUNCTION LIST


//TXVERTEX DEFINITION

class TXVERTEX
{
public:
float x;
float y;
float z;
float rhw;
D3DCOLOR color;
float u;
float v;
public:
TXVERTEX();
void Init(int);
};

TXVERTEX::TXVERTEX()
{
x=0;
y=0;
z=0;
rhw=0;
color=0;
u=0;
v=0;
}

void TXVERTEX::Init(int FLAG)
{
TXVERTEX::z=0.0f;
TXVERTEX::rhw=1.0f;
TXVERTEX::x=0;
TXVERTEX::y=0;
switch(FLAG)
{
case VT_UP_LEFT:
TXVERTEX::u=0.0f;
TXVERTEX::v=0.0f;
break;
case VT_UP_RIGHT:
TXVERTEX::u=1.0f;
TXVERTEX::v=0.0f;
break;
case VT_LO_LEFT:
TXVERTEX::u=0.0f;
TXVERTEX::v=1.0f;
break;
case VT_LO_RIGHT:
TXVERTEX::u=1.0f;
TXVERTEX::v=1.0f;
}
}
//END TXVERTEX DEFINITION


class DSPRITE
{
public:
DSPRITE();
//DSPRITE(LPDIRECT3DDEVICE9*);

HRESULT LoadSprite(char*, LPDIRECT3DDEVICE9*);
void SetVerticeCoords(int, int);
void Init();
void Render(int, int, int, LPDIRECT3DDEVICE9*);
private:
LPDIRECT3DVERTEXBUFFER9 VertexBuffer;
LPDIRECT3DTEXTURE9 Texture;

int xWidth;
int yHeight;

int xCoord;
int yCoord;

private:
LPDIRECT3DSURFACE9 SpriteSurface;
};
//***************************
// DSPRITE FUNCTIONS*********
//***************************
//***************************
DSPRITE::DSPRITE()
{
DSPRITE::SpriteSurface=0;
DSPRITE::VertexBuffer=0;
DSPRITE::xWidth=0;
DSPRITE::yHeight=0;
DSPRITE::xCoord=0;
DSPRITE::yCoord=0;
}
/*DSPRITE::DSPRITE(LPDIRECT3DDEVICE9* ppDev)
{
(*ppDev)->CreateVertexBuffer(sizeof(TXVERTEX) * 4, 0, D3DFVF_TXVERTEX, D3DPOOL_MANAGED, &(DSPRITE::VertexBuffer), NULL);
(*ppDev)->SetStreamSource(0, DSPRITE::VertexBuffer, 0, sizeof(TXVERTEX));
}*/

HRESULT DSPRITE::LoadSprite(char* FilePath, LPDIRECT3DDEVICE9* ppDev)
{
D3DXIMAGE_INFO ImageInfo;
D3DCOLOR ColorKey=0xFFFF00FF;
if (FAILED(D3DXCreateTextureFromFileEx(*ppDev, FilePath, 0, 0, 1, 0, ImageInfo.Format/*??????*/, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, ColorKey, &ImageInfo, NULL, &(DSPRITE::Texture))))return E_FAIL;
DSPRITE::xWidth=ImageInfo.Width;
DSPRITE::yHeight=ImageInfo.Height;
return S_OK;
}
void DSPRITE::Init()
{
TXVERTEX Vertex[4];
DSPRITE::VertexBuffer->Lock(NULL, sizeof(TXVERTEX)*4, (void**)Vertex, NULL);
Vertex[0].Init(VT_UP_LEFT);
Vertex[1].Init(VT_UP_RIGHT);
Vertex[2].Init(VT_LO_LEFT);
Vertex[3].Init(VT_LO_RIGHT);
DSPRITE::VertexBuffer->Unlock();
}

void DSPRITE::Render(int Cam, int x, int y, LPDIRECT3DDEVICE9* ppDev)
{
TXVERTEX Vertex[4];
DSPRITE::VertexBuffer->Lock(NULL, sizeof(TXVERTEX)*4, (void**)Vertex, NULL);

Vertex[0].x=(float)x-Cam;
Vertex[0].y=(float)y;
Vertex[1].x=(float)(Vertex[0].x)+DSPRITE::xWidth;
Vertex[1].y=(float)y;
Vertex[2].x=(float)(Vertex[0].x);
Vertex[2].y=(float)y-(DSPRITE::yHeight);
Vertex[3].x=(float)(Vertex[1].x);
Vertex[3].y=(float)(Vertex[2].y);
(*ppDev)->SetTexture(0, DSPRITE::Texture);
(*ppDev)->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
DSPRITE::VertexBuffer->Unlock();
}
[\source]


[edited by - Ademan555 on December 1, 2003 10:51:02 AM]

Share this post


Link to post
Share on other sites