• Advertisement

Archived

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

cannot render a quad (DIFFUSE only)

This topic is 5062 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

for some reason, i'm trying to render a quad with four different colors, but it only renders green... here's my code: vertex buffer creation:
	g_pd3dDevice->CreateVertexBuffer(sizeof(sColoredVertex)*4,NULL,
				D3DFVF_COLOREDQUAD,D3DPOOL_MANAGED,&g_pd3dVB,NULL);


defines:
   
const DWORD D3DFVF_COLOREDQUAD	= D3DFVF_XYZRHW | D3DFVF_DIFFUSE;

struct sColoredVertex
{
	FLOAT x,y,z,rhw;
	DWORD dwColor;
};



quad drawing:
   
void DrawQuad(int x0,int y0,int x1,int y1,DWORD *dwColor)
{
	//draw

	sColoredVertex* vertices;

	//set the stream source

	g_pd3dDevice->SetFVF(D3DFVF_COLOREDQUAD);
	g_pd3dDevice->SetStreamSource(0,g_pd3dVB,0,sizeof(sColoredVertex));

	g_pd3dVB->Lock(0,0,(void**)&vertices,NULL);

	vertices[0].dwColor = dwColor[0];
	vertices[0].rhw = 1.0f;
	vertices[0].x = (FLOAT)x0;
	vertices[0].y = (FLOAT)y0;
	vertices[0].z = 0.0f;

	vertices[1].dwColor = dwColor[1];
	vertices[1].rhw = 1.0f;
	vertices[1].x = (FLOAT)x1;
	vertices[1].y = (FLOAT)y0;
	vertices[1].z = 0.0f;

	vertices[2].dwColor = dwColor[2];
	vertices[2].rhw = 1.0f;
	vertices[2].x = (FLOAT)x1;
	vertices[2].y = (FLOAT)y1;
	vertices[2].z = 0.0f;


	vertices[3].dwColor = dwColor[3];
	vertices[3].rhw = 1.0f;
	vertices[3].x = (FLOAT)x0;
	vertices[3].y = (FLOAT)y1;
	vertices[3].z = 0.0f;

	g_pd3dVB->Unlock();

	g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,0,2);
		
}
can anybody shed light on this? EDIT: i viewed it one more time: it rendered the colors correctly for only a frame, so i just saw a flicker of red/blue/green, but then it only rendered the green side.

		DWORD dwColor[4] = {0xff000000,0xff00ff00,0xffff0000,0xff0000ff};

		DrawQuad(0,0,640,480,dwColor);

[edited by - Cipher3D on April 12, 2004 7:46:19 PM]

Share this post


Link to post
Share on other sites
Advertisement
questions: have you checked the DWORD array you send in for the colors (i assume you have)?

EDIT: you must have been editing while i was writing.

other than that, i cant see where your going wrong...



[edited by - syrillix on April 12, 2004 7:54:06 PM]

Share this post


Link to post
Share on other sites
This is the code that I used and it works fine for me. Granted its textured, but if u replace that with colors it should work. When I started I used just colors at first.


struct VertexXYZRHW_TU_TV
{
FLOAT x, y, z, rhw; // X, Y, Z and the RCW (for 2d Drawings)
FLOAT tu, tv; // texture coordinates
};
#define D3DFVF_VERTEX_XYZRHW_TEX ( D3DFVF_XYZRHW | D3DFVF_TEX1 )


VertexXYZRHW_TU_TV vert[] =
{
{ static_cast(rect.left), static_cast(rect.top), 0.5f, 1.0f, 0.0f, 0.0f, }, // x, y, z, rhw, tu, tv
{ static_cast(rect.right), static_cast(rect.top), 0.5f, 1.0f, 1.0f, 0.0f, },
{ static_cast(rect.right), static_cast(rect.bottom), 0.5f, 1.0f, 1.0f, 1.0f, },
{ static_cast(rect.left), static_cast(rect.bottom), 0.5f, 1.0f, 0.0f, 1.0f, },
};

if( FAILED( g_device3D->CreateVertexBuffer( 4*sizeof(VertexXYZRHW_TU_TV),
D3DUSAGE_WRITEONLY , D3DFVF_VERTEX_XYZRHW_TEX, D3DPOOL_MANAGED, &m_vbVertex_Buff, 0 ) ) )
{
return E_FAIL;
}

VertexXYZRHW_TU_TV* vertex_buff;
if( FAILED( m_vbVertex_Buff->Lock( 0, 4*sizeof(VertexXYZRHW_TU_TV), (void**)&vertex_buff, 0 ) ) )
{
return E_FAIL;
}


memcpy( vertex_buff, vert, sizeof(vert) );
m_vbVertex_Buff->Unlock();

if( FAILED( D3DUtil_CreateTexture( g_device3D, _T(pic_filename),
&m_texImage ) ) )
{
return E_FAIL;
}

Share this post


Link to post
Share on other sites
i know it WORKS, because i saw a flash of the colors i wanted to see, but after that flicker of "correctness," it was just green. Here's a screen shot:



textured quads work for me, i'm writing a 2d sprite engine, but I can't draw colored quads correctly...grrr....

EDIT: note, i'm locking and unlocking the vertex buffer every frame, is that a reason why? should i just lock it once, fill in the data, and that's it?

EDIT2: no texture stages, and yes i did set textures before in the program, but i drew the quad first...wait a minute..that might be the cause...

EDIT3: Got it to work! I just had to g_pd3dDevice->SetTexture(0,NULL) in order for it to work!
thanks a bunch..
[edited by - Cipher3D on April 12, 2004 8:06:27 PM]

[edited by - Cipher3D on April 12, 2004 8:07:16 PM]

[edited by - Cipher3D on April 12, 2004 8:09:54 PM]

Share this post


Link to post
Share on other sites
since i didn''t want to bother asking in a second post, might as well ask here.

my question is, i''m using directinput for mouse input, but i''m using a windowed application. Since directinput only sends deltas, i can''t get the exact location of the mouse, relative to the client area of the application. whenever i click on a GUI button in my app, my mouse cursor is isually in a place where i don''t want it to be (such as my MSVC program), and then it switches to the program i accidentally clicked on...

Share this post


Link to post
Share on other sites
Either use GetCursorPos to get mouse pos in screen coordinates and then ScreenToClient, or add up the deltas for yourselves. Don''t forget to clip the mouse pos on the screen borders though, the delta doesn''t care about that.

Share this post


Link to post
Share on other sites
Solved it via a weird hack: I just set the mouse to exclusive mode, so no other apps could access my mouse...

my precious...yes...precciousssss

Share this post


Link to post
Share on other sites

  • Advertisement