Skip to main content
GameDev.net gamedev.net
🔒 Locked

Triangle Rendering Black [omg fixxored]

Started by Mushu Mar 23, 2005 at 9:35 PM 7 replies 2.7k views
Original Post
Mushu
Mushu
Yeah, haven't worked out the damn problem yet. Looked everywhere - maybe a third party will catch what I'm overlooking. Here's everything you need:
// I'm rendering a triangle on a blue surface. Each
// vertex should have 255 of 1 RGB component. It
// renders black - not color. Can't seem to figure
// out why... 

// there are no errors, compile/linker/runtime/stripper.

// FVF
#define FVF_Vertex_TL (D3DFVF_XYZRHW|D3DFVF_TEX1|D3DFVF_DIFFUSE)
struct sVertex_TL {
	D3DXVECTOR3 p;
	FLOAT rwh;
	D3DXVECTOR2 t;
	D3DCOLOR c;
};

// render states
		D3DDevice->SetVertexShader(FVF_Vertex_TL);
		D3DDevice->SetRenderState(D3DRS_LIGHTING, false);
		D3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

// vertex data
sVertex_TL mV_TL(D3DXVECTOR3 p, FLOAT rwh, D3DXVECTOR2 t, D3DCOLOR c);
	sVertex_TL verts[3];
	verts[0] = mV_TL(mV(0,0,0),1,mV(0,0),D3DCOLOR_XRGB(255,0,0));
	verts[1] = mV_TL(mV(0,100,0),1,mV(0,0),D3DCOLOR_XRGB(0,255,0));
	verts[2] = mV_TL(mV(100,0,0),1,mV(0,0),D3DCOLOR_XRGB(0,0,255));

// render call
	if (FAILED(myDx->getDev()->DrawPrimitiveUP(D3DPT_TRIANGLELIST,1,verts,sizeof(sVertex_TL)))) {
		err("omg-failed"); }


(nice version) Thanks for the help guys! [Edited by - Mushu on March 23, 2005 11:25:35 PM]
Muhammad Haggag
Muhammad Haggag
OMG, Mushu's actually doing a technical post. THE END IS NIGH...

Ok, anyway:
1) When using FVFs, your vertex structure must conform to a certain "order" - basically, some elements must come before some other elements. Why? Because SetFVF creates a vertex declaration, which says which component consists of what and comes when
e.g. position comes first (offset = 0) and is 4d vector (size = float * 4)

So when you use SetFVF, it can't examine your vertex structure to determine the order. In your case, the assumed order is:
Position
Diffuse
TexCoords

2) Given that you have texCoords, you'll need to SetTexture(0, my_texture) somewhere

3) You will also need to setup your texture stage states. You need to tell Direct3D how to use the color and texture. For example:
SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

This tells Direct3D to get the color from the 'diffuse' component (and ignore the texture), and to disable stage 1 because we're not using it (This is important! Always disable the first stage you don't use, both color and alpha ops)

4) This piece of error-checking wisdom:
if (FAILED(myDx->getDev()->DrawPrimitiveUP(D3DPT_TRIANGLELIST,1,verts,sizeof(sVertex_TL)))) {		err("omg-failed!!!1111!!");}

can be better done using the DXGetErrorString9 and DXGetErrorDescription9 functions, which do exactly what their names say.

Mushu
Mushu
Oh, duh - the textures. Completely forgot about those.

And yeah, I figured there was something wrong with my FVF. Back in the day I just stole other people's code and patched it together; actually writing it in a real language is a wee bit different.

As for the error checking, yeah, my err(..) function could be a little bit more detailed. But, eh. If it were up to me, my error boxes would be filled with garbage, and with "yes/no" options. Both options would have the same effect - a forced reboot.

Come to think of it, it is up to me. My my my... things are gonna get crazy in here.

*ahem* DANKE!!!
edit: omg I never rated you up. *Mushu attacks for +7HP damage
Muhammad Haggag
Muhammad Haggag
Quote:
Original post by Mushu
As for the error checking, yeah, my err(..) function could be a little bit more detailed. But, eh. If it were up to me, my error boxes would be filled with garbage, and with "yes/no" options. Both options would have the same effect - a forced reboot.

Error dialogs are for wimps. Most of them, anyway. My #1 rule of modern smart UI design is:
The user knows NOTHING. He's not a programmer anyway, what does he know? And even if he's a programmer, he's not ME anyway, so still, what does he know? Nothing

A straight silent reboot is the only way to go. I'd even go further and remove the OS, if possible - If my app crashes or fails, the system is obviously and most definitely h4x0r3d, and needs a clean install to work.

And, even in the rare occasions where an error dialog is needed, I follow my #2 rule of modern smart UI design:
Design for DUMB RETARDS. If a dumb, retarded user can't figure out how to run your application, you - in my most unhumble opionion - sux0rz. Do away with dialog box choices/buttons. Dialog boxes should be used for one purpose, and one purpose only: Notifying the user of what you're going to do, doing a 10 second countdown, and doing it anyway (or doing other things - it really doesn't matter).

Quote:
Come to think of it, it is up to me. My my my... things are gonna get crazy in here.

If you're ever in need of a blood-thirsty tester, you know where to look.

Quote:
*ahem* DANKE!!!

KEIN PROBLEM!!111
(On a sidenote: I just noticed you use size tags without surrounding the attribute value with double or single quotes. How sad [sad])

Drew_Benton
Drew_Benton
Quote:
Original post by Coder
If you're ever in need of a blood-thirsty tester, you know where to look.


Is that an open invitation? [grin]
Muhammad Haggag
Muhammad Haggag
Quote:
Original post by Drew_Benton
Quote:
Original post by Coder
If you're ever in need of a blood-thirsty tester, you know where to look.


Is that an open invitation? [grin]

Well, if you can show me some PICTARS, I might be in...

Mushu
Mushu
Quote:
Original post by Coder
Quote:
Original post by Drew_Benton
Quote:
Original post by Coder
If you're ever in need of a blood-thirsty tester, you know where to look.


Is that an open invitation? [grin]

Well, if you can show me some PICTARS, I might be in...



I almost posted a *.bmp... but then I decided not to be so cruel.
So I wrote the HTML tags in all lower case, just like you did. SHAME!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.