# There is no square

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

## Recommended Posts

...and no unhappy icon either. [sad] Disclaimer: Yes, I know the code is a mess, so on and so forth. There are a lot of things I could have done differently yadda yadda it doesn't conform to the standard blah blah and if anyone had to use this code professionally they'd probably sue because their eyes melted upon viewing it. Anyway; I'm trying to render in 3D. Right now I can render in 2D fine, however, when I attempt to use matrices and go into 3D, nothing gets rendered. Well, it renders (no error codes), you just can't see it. Naturally, this is bad. So, I've been preening over it with a bunch of different people, but still can't seem to figure out what's going wrong. The problem must be either in the FVF or the matrices, because that's the only thing that is changed between the 2D and 3D rendering.. modes? You get the drift. Anyway, it'd be too tedious for me to post the code here. So I packed it all away into a handy zip (DOWNLOAD NOW, 21.7KB) In the code, you'll see that a vertex buffer is set up, but its actually bypassed (Evil Steve wanted to rule out any problems in the VB) with a call to DrawPrimitiveUP. What else did we rule out... bah, I can't remember. Yeah, I know the code's a mess, but I'd really appreciate it if you could just take a look at it. At this point, I really don't expect anyone to find the problem, just because I tend to be a pessimestic bastard. But yeah, it pointless to code anything else at this point if nothing (3D) actually renders... Thanks for your help guys.
EDIT: It has been brought to my attention that it doesn't even compile in modern compilers. I guess that's what I get for getting stuck with MSVC6, huh? EDIT2:
Quote:
 Direct3D8: (ERROR) :*** Exception in d:\builds\nt32_chk\multimedia\directx\dxg\d3d8\fe\vshader.cpp Line: 666 Evil Steve... Wtf lol 666 oh my. in the vertex shader too The antichrist knome is in your code. Ok, it errors at: if(FAILED(myDx->getDev()->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,verts,sizeof(sVertex_UL))))

##### Share on other sites
Quote:
 Original post by MushuEDIT: It has been brought to my attention that it doesn't even compile in modern compilers. I guess that's what I get for getting stuck with MSVC6, huh?

To fix that all you (People helping out using VS7) need to do is make (cStateManager.h):
class cStateManager {	typedef struct sState {		void (*function)(cStateManager*, void*);		sState* next;

Into:
class cStateManager {	protected:	typedef struct sState {		void (*function)(cStateManager*, void*);

Then it will compile at least. Now there will be one linker error so you need to go to Project->Properties->Linker and add "libci.lib" to the "Ignore Specific Library".

It will now compile, link, and run. As for the reason it is messed up, can't offer much help there since I don't have any DX skills, but if anything does come up...[wink]

##### Share on other sites
Yes, this is the debug output it gives:

Direct3D8: (ERROR) :Stream 0 stride should match the stride, implied by the current vertex shader

The other thing I found was that your camera position is a bit shady. You have an eye position of (0, 20, 0) and are looking at (0,-1,0). But your rectangle is set up in 3D space at (0, 0, 100) to (200, 200, 100). It's definetly not going to be in view, because you are looking straight at the ground.

##### Share on other sites
Quote:
 Original post by circlesoftYes, this is the debug output it gives:Direct3D8: (ERROR) :Stream 0 stride should match the stride, implied by the current vertex shader
On my machine I just get the exception posted in Mushu's excerpt.
And setting the FVF just before the DPUP() call doesn't seem to help either, even though the FVF matches the stride...

##### Share on other sites
Quote:
 Original post by circlesoftThe other thing I found was that your camera position is a bit shady. You have an eye position of (0, 20, 0) and are looking at (0,-1,0). But your rectangle is set up in 3D space at (0, 0, 100) to (200, 200, 100). It's definetly not going to be in view, because you are looking straight at the ground.

Oh, yeah, Steve had me change the z-values from 0 to 100 to check the z-buffer. Regardless, setting them back to 0 and putting the primitives back in the viewing region makes no difference, they still can't be seen. Nice catch, though.

##### Share on other sites
Interesting... Trying to draw 0 primitives gives:
Quote:
 Direct3D8: (ERROR) :*** Exception in d:\builds\nt32_chk\multimedia\directx\dxg\d3d8\fe\d3dbase.cpp Line: 3455

##### Share on other sites
Quote:
 Original post by Evil SteveOn my machine I just get the exception posted in Mushu's excerpt.

Do you have the debug runtime selected and output turned up?

Quote:
 And setting the FVF just before the DPUP() call doesn't seem to help either, even though the FVF matches the stride...

The vertex structure doesn't match the FVF, though. The FVF is:

D3DFVF_XYZ|D3DFVF_TEX0|D3DFVF_DIFFUSE

But the vertex structure is:

struct sVertex_UL {
D3DXVECTOR3 p;
D3DCOLOR c;
D3DXVECTOR2 t;
};

The vertex structure should be:

struct sVertex_UL {
D3DXVECTOR3 p;
D3DXVECTOR2 t;
D3DCOLOR c;
};

##### Share on other sites
I think I figured it out [grin] I looked at NeHe's DX 9 code and did a little comparing.

In your: virtual void setState3D_UL(D3DXVECTOR3 eye=D3DXVECTOR3(0.0f,3.0f,-5.0f), D3DXVECTOR3 at=D3DXVECTOR3(0.0f,0.0f,0.0f)) { function in cDX.h I made these changes and it works now.
virtual void setState3D_UL(D3DXVECTOR3 eye=D3DXVECTOR3(0.0f,3.0f,-5.0f), D3DXVECTOR3 at=D3DXVECTOR3(0.0f,0.0f,0.0f)) {		D3DDevice->SetVertexShader(FVF_Vertex_UL);		D3DDevice->SetRenderState(D3DRS_LIGHTING, false);		D3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);		D3DDevice->SetRenderState(D3DRS_ZENABLE,  true);				/*D3DXMatrixIdentity(&matWorld);		D3DDevice->SetTransform(D3DTS_WORLD, &matWorld);		D3DXMatrixLookAtLH(&matView, &eye, &at, &D3DXVECTOR3(0.0f, 1.0f, 0.0f));		D3DDevice->SetTransform(D3DTS_VIEW, &matView);		D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4.0f, 1.0f, 1.0f, 1000.0f );		D3DDevice->SetTransform(D3DTS_PROJECTION, &matProj);*/		D3DXMATRIXA16 matProjection;						// Create A Projection Matrix		// Calculate The Aspect Ratio Of The Window		D3DXMatrixPerspectiveFovLH(&matProj, 45.0f, (float)640/(float)480, 0.1f, 100.0f );		D3DDevice->SetTransform( D3DTS_PROJECTION, &matProj );		D3DXMatrixIdentity(&matProj);	}

Here's the image. Don't ask me to explain [lol].

##### Share on other sites
Quote:
 Original post by circlesoftThe vertex structure should be:struct sVertex_UL { D3DXVECTOR3 p; D3DXVECTOR2 t; D3DCOLOR c;};

I'm pretty sure color comes before texture in Dx8.

Testing Drew_Benton's fixes.

##### Share on other sites
Quote:
 Original post by circlesoftDo you have the debug runtime selected and output turned up?
I found that if I click "continue" at the breakpoint, it carries on and gives the error you said.

I see the problem - circlesoft was right(ish). The FVF says TEX0 - no texture coords, but theres 1 set in the vertex struct.

I thought that colour comes before texture coords?

##### Share on other sites
Quote:
 Original post by Evil SteveI thought that colour comes before texture coords?

Ah, perhaps you guys are correct. It's been a *very* long time since I've used FVFs and the FFP. [wink]

##### Share on other sites
Well... I can also get what Drew sees, but it involves disabling the view matrix, which is a pain. I've tried setting the eye to (0,0,0), the lookat to (0,0,1), and the clip planes to 0.1f and 100.0f, and moved all the vertices like this, but it dtill doesn't want to work...
verts[0] = mV_UL(mV(-10,-100,50),mV(0,0),D3DCOLOR_XRGB(0,0,0));verts[1] = mV_UL(mV(-100,100,50),mV(0,1),D3DCOLOR_XRGB(0,255,0));verts[2] = mV_UL(mV(100,-100,50),mV(1,0),D3DCOLOR_XRGB(0,0,255)); verts[3] = mV_UL(mV(100,100,50),mV(1,1),D3DCOLOR_XRGB(255,0,0));

P.S. Drew, the FOV is in radians, not degrees [wink]

##### Share on other sites
Ok, it works perfectly fine now. I didn't realise that the parameters were changed (the default arguments). Changing gMain.cpp:34 to this makes it work fine: myDx.setState3D_UL();

##### Share on other sites
Its crashing on my system (I'm using the code you sent over) on the DrawPrimitive call (I think, I'll add some logging stuff tommorrow). BSOD reports error 0x000000D5, which is really weird, because I'm running winME. Apparently, that error shouldn't even be possible (or so I read; it was implemented on XP? I dunno)

Probably bad data somewhere, either in the vertex buffer, or the vertex shader is reading something its not supposed to be, or whatever. Actually, I'll go ahead and upload a binary, maybe its just this system that's b0rked (yay for shitty OS'es)

##### Share on other sites
Yep, it works okay for me.

I think your OS was borked the second you (or the factory dude) put the WinMe disc in the tray [wink]

##### Share on other sites
Quote:
 Original post by MushuIts crashing on my system (I'm using the code you sent over) on the DrawPrimitive call (I think, I'll add some logging stuff tommorrow). BSOD reports error 0x000000D5, which is really weird, because I'm running winME. Apparently, that error shouldn't even be possible (or so I read; it was implemented on XP? I dunno)Probably bad data somewhere, either in the vertex buffer, or the vertex shader is reading something its not supposed to be, or whatever. Actually, I'll go ahead and upload a binary, maybe its just this system that's b0rked (yay for shitty OS'es)(Download Binary, 224KB)
Have you tried running the SDK samples? Perhaps your system or DX is borked somehow.

Quote:
 Original post by circlesoftI think your OS was borked the second you (or the factory dude) put the WinMe disc in the tray [wink]
Oh, he already gets enough stick about using WinME in A Place That Does Not Exist [smile]