Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - XiA

Pages: [1]
1
Just wanted to report back:

My code is working now (and when I say "my code", I most certainly do not mean my code, I mean the code you wrote and that I stole/modified/used/learned from). Again, thank you!

2
Ok, it was viewport MinZ/MaxZ messing things up, changed it to default config and added a textured cube model to test rotation/translation.
It's hard to spot those problems without seeing the complete non working code :)

Damn, yup, you sure got the stuff working! Thank you SO MUCH for this, I really appreciate it, I've been stuck on this for 4 days now (well, in all honesty not full-time, luckily). Thanks!

3
If you like, you can post your complete msvc source (minimal framework), and I can test it here.

Thanks for the offer! I've sent you a PM!

4
Try changing your Z-value of the near view-plane to 1.0f instead -1.0f

Yeah, I changed that as a test and forgot to change it back. But my polygons are showing, the problem is they aren't responding to the SetTransform(). Or at least that's what it looks like. But thanks anyway.

5
none of the transformations are being done.

...IS being done. Performed. Executed.

6
I am a bit wondering on what you are trying to do.

Definitely a valid question! My end goal is to be able to do demos using pixel shaders. And all the reading up I've done have pointed in the direction that I need to get rid of my current code that rotates/scales/transforms manually, and then draws, and replace that with code that sends all these tasks to the hardware.

In fact, you will just have the cube rotated of 0.9 on 1 axis (because I think you are killing the matrices where you have done the rotation on the other axis).
Moreover, the cube will not move at all, because you are not using some kind of counter ... that would make the rotation angle to change.

Agreed. This code wouldn't animate at all. My *real* problem, however, is that all this code for transforming/rotating does NOTHING. If I comment it out, I get the exact same result.

So, here are my thoughts:

- Put a counter to change rotation angle
- Debug the code to show the values in the matrices ... when you are passing it to the pipeline.

Yeah, the matrices look fine, they're changed as the code progresses. If I were to pinpoint a single point of failure, it's as if my SetTransform() call does NOTHING to the DrawPrimitive() call. Or maybe it's affecting a different StreamSource? The code is drawing exactly what I'm putting in the vertex buffer, but none of the transformations are being done.

Oh, and I've tried animating the values for the rotation matrix, made no difference whatsoever; my polygon object just sits there, as if to taunt me  :)

7
Hello,

I would have done the following (maybe I am silly because I am not simplifying stuff)
Code: [Select]
D3DXMatrixMultiply(&X_H3D_world_matrix,&X_H3D_world_matrix,&X_H3D_rotation_matrix);
D3DXMatrixMultiply(&X_H3D_world_matrix,&X_H3D_world_matrix,&X_H3D_translation_matrix);

Ah, good thinking! But sadly, it didn't make a difference. Thanks for the idea tho!

8
Hi!

I'm trying to make hardware scaling/rotating/translating work in DirectX9, using the Drunken Hyena example at
http://www.drunkenhyena.com/cgi-bin/view_cpp_article.pl?chapter=2;article=28
as a template.

Here's my init code:
Code: [Select]
// g_pd3dDevice is LPDIRECT3DDEVICE9
D3DXMatrixIdentity(&X_H3D_view_matrix);
D3DXMatrixIdentity(&X_H3D_projection_matrix);
D3DXMatrixIdentity(&X_H3D_rotation_matrix);
D3DXMatrixIdentity(&X_H3D_translation_matrix);
D3DXMatrixIdentity(&X_H3D_world_matrix);

X_H3D_eye_vector=D3DXVECTOR3( 0.0f, 0.0f,-8.0f );
X_H3D_lookat_vector=D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
X_H3D_up_vector=D3DXVECTOR3(0.0f,1.0f,0.0f);
D3DXMatrixLookAtLH(&X_H3D_view_matrix,&X_H3D_eye_vector,
                   &X_H3D_lookat_vector,
                   &X_H3D_up_vector);
g_pd3dDevice->SetTransform(D3DTS_VIEW,&X_H3D_view_matrix);

X_H3D_aspect=((float)WindowWidth / (float)WindowHeight);
D3DXMatrixPerspectiveFovLH(&X_H3D_projection_matrix,
                           D3DX_PI/4,
                           X_H3D_aspect,
                           -1.0f,
                           100.0f );
g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &X_H3D_projection_matrix);

D3DXMatrixIdentity(&X_H3D_world_matrix);
g_pd3dDevice->SetTransform(D3DTS_WORLD,&X_H3D_world_matrix);

And this is the code between BeginScene() and EndScene(), which is later Present():ed:
Code: [Select]
// X_TriangleBuffer is a vector containing int's pointing to vertices in X_VertexBuffer
// X_VertexBuffer is a vector containing vertices
  int numTriangles=X_TriangleBuffer.size();
  CUSTOMVERTEX* vertices=NULL;
  CUSTOMVERTEX thisVertex;
  vertices=new CUSTOMVERTEX[3*numTriangles];
  int numVertexIndex=0;
  DWORD colThis=0xff00ff00;

  // Commented data is just to test if the raw vertex data looks the way it should
  const float numOffsetX=0; // WindowWidth/2;
  const float numOffsetY=0; // WindowHeight/2;
  const float numOffsetZ=0; // 30;

  for(int i=0;i<(int)X_TriangleBuffer.size();i++){
    X_Triangle T=X_TriangleBuffer[i];
    int numA=T.a;
    int numB=T.b;
    int numC=T.c;
    thisVertex.X=(float)X_VertexBuffer[numA].x;
    thisVertex.Y=(float)X_VertexBuffer[numA].y;
    thisVertex.Z=(float)X_VertexBuffer[numA].z;
    thisVertex.RHW=0.2f;
    thisVertex.COLOR=colThis;
    thisVertex.X+=numOffsetX;
    thisVertex.Y+=numOffsetY;
    thisVertex.Z+=numOffsetZ;
    vertices[numVertexIndex++]=thisVertex;
    thisVertex.X=(float)X_VertexBuffer[numB].x;
    thisVertex.Y=(float)X_VertexBuffer[numB].y;
    thisVertex.Z=(float)X_VertexBuffer[numB].z;
    thisVertex.RHW=0.2f;
    thisVertex.COLOR=colThis;
    thisVertex.X+=numOffsetX;
    thisVertex.Y+=numOffsetY;
    thisVertex.Z+=numOffsetZ;
    vertices[numVertexIndex++]=thisVertex;
    thisVertex.X=(float)X_VertexBuffer[numC].x;
    thisVertex.Y=(float)X_VertexBuffer[numC].y;
    thisVertex.Z=(float)X_VertexBuffer[numC].z;
    thisVertex.RHW=0.2f;
    thisVertex.COLOR=colThis;
    thisVertex.X+=numOffsetX;
    thisVertex.Y+=numOffsetY;
    thisVertex.Z+=numOffsetZ;
    vertices[numVertexIndex++]=thisVertex;
  }

  struct D3DVIEWPORT9{
    DWORD X;
    DWORD Y;
    DWORD Width;
    DWORD Height;
    float MinZ;
    float MaxZ;
  };

  X_H3D_view_port.X=0;
  X_H3D_view_port.Y=0;
  X_H3D_view_port.Width=WindowWidth;
  X_H3D_view_port.Height=WindowHeight;
  X_H3D_view_port.MinZ=-100.0f;
  X_H3D_view_port.MaxZ=100.0f;

  g_pd3dDevice->SetViewport(&X_H3D_view_port);

  g_pd3dDevice->SetRenderState(D3DRS_LIGHTING,FALSE);

  g_pd3dDevice->CreateVertexBuffer((3*numTriangles)*sizeof(CUSTOMVERTEX),
                             0,
                             CUSTOMFVF,
                             D3DPOOL_MANAGED,
                             &v_buffer,
                             NULL);
  VOID* pVoid;    // a void pointer

  v_buffer->Lock(0, 0, (void**)&pVoid, 0);
  memcpy(pVoid, vertices, 3*numTriangles*sizeof(CUSTOMVERTEX));
  v_buffer->Unlock();

  g_pd3dDevice->SetFVF(CUSTOMFVF);

  g_pd3dDevice->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));

  D3DXMatrixRotationY(&X_H3D_rotation_matrix,0.9f);
  D3DXMatrixRotationX(&X_H3D_rotation_matrix,0.9f);

  D3DXMatrixTranslation(&X_H3D_translation_matrix,0.0f,0.0f,0.0f);
  D3DXMatrixMultiply(&X_H3D_world_matrix,&X_H3D_rotation_matrix,&X_H3D_translation_matrix);

  g_pd3dDevice->SetTransform(D3DTS_WORLD,&X_H3D_world_matrix);

  g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, //PrimitiveType
                              0,                  //StartVertex
                              numTriangles);      //PrimitiveCount

  delete [] vertices;

My vertex data is fine, and the stuff is drawn, but if I comment out all the rotation matrix stuff, I get the exact same result. It just does NOTHING.

I'm sure I'm doing something wrong here, and quite probably even something really stupid, and I'd appreciate any help here.

Thanks in advance!

9
Code: [Select]
unsigned char *dst= (unsigned char*) rect.pBits;
for (int y=0; y<height; y++)
{
  _asm {
    mov edi,dst    // destination pointer
    mov ecx,width  // number of argb pixels to fill
    mov eax,color  // argb color
    rep stosd
  }
  dst += rect.Pitch;
}

Yup, this is actually SLIGHTLY faster, about 1.3ms on this laptop, thanks! 8-)

10
Code: [Select]
(code)

Ah, it's THAT easy! Thanks a bunch!

11

In this special case of a managed resource it might be save to assume no additional pitch but I'd never count on it.
Actually there can be quite a lot of pitch on gpu resources which is useless to clear.
Nvidia usually uses padding to the next power of two, so eg for an 32bit texture of 640 pixels width (2560 bytes) you'd actually be clearing 4096 bytes for each scanline...

Very good point!

Ok, so let's assume I have a DWORD LineWidth in C++, how do I put that in ecx?

12
Try this code below, not sure if it will perform any better than MSVC for/loop.


Yup, that made a measurable difference! My C++ for() loop averaged roughly 1.9 ms on this machine, your asm code averages just below 1.4 ms! Thanks a lot mate, I'm keeping that one. 8-)

13
So I assume your using a "IDirect3DTexture9" texture ? Then locking it to draw and unlocking it after? If so then there probably isnt a hardware accelerated way to do it, since your only actually using the hardware to render the texture at some point.

Yeah, you might be right about that...

But if your using a constant value across the whole texture maybe you can fill faster, Perhaps if you post the code your using to clear the texture someone might offer a faster way.

Absolutely, good idea! Here's my code (be gentle with me, I'm a noob at both DX and C++ 8-)  ):
Code: [Select]
    hr=texturePixelsBlock->LockRect(0,&rectPixelsLocked, NULL, D3DLOCK_NOSYSLOCK);
    if(SUCCEEDED(hr)){
      ////////////////////////////////////////////////////////////////
      // The actual drawing

      pPixel32 = (DWORD *)rectPixelsLocked.pBits;
      pPixel8 = (BYTE *)rectPixelsLocked.pBits;

      // Clear texture
      if(1==1){
        for(signed int i=(rectPixelsLocked.Pitch/4);i<((rectPixelsLocked.Pitch/4)+WindowWidth*WindowHeight);i++){
          pPixel32[i]=0x00000000;
        }
      }
      // And all the rest of the drawing follows here
    }

It's been a couple of years since I did 386 asm, but I suspect this code is unlikely to compile to something *really* fast, like a strcpy, but then again, I suspect there's tons of new instructions (i e since the 30386DX was the hottest CPU on the market, LOL) for this that VC++ might make of it. Maybe?

Also, thanks for taking the time to help out here, I really appreciate it!

14
Code: [Select]
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, iColor, 1.0f, 0 )
Thats one way to clear the backbuffer in dx9, Clear is a method of the direct3d9 device and iColor is in my case a 32bit int for the XRGB color.

Hi! Thanks for pitching in, but as far as I can see, device->Clear() only works on buffers. I may very well be wrong, and if so, I'd welcome someone letting me know 8-)

15
For clearing something, in Dx10 (sorry, I don't have code for Dx9) it's:
Code: [Select]
const float background_colour[] = { 0, 0, 0.25f, 0 };

    _dev->ClearRenderTargetView( _backbuffer_view, background_colour );

I guess for Dx9 it's similar.

Thanks for the reply, but that method doesn't seem to be available in DX9. I did find ColorFill() tho, but that works on a surface, and VC++ screams "cannot convert parameter 1 from 'LPDIRECT3DTEXTURE9' to 'IDirect3DSurface9 *'" at me when I try.

Any idea on how to make that work, like a way to create a dummy surface and point it to my texture?

16
Not being able to use the texture as a rendertarget is just fine by me; I have a background image, this texture (where I'm drawing realtime stuff like lines, circles etc) and then D3DX sprites on top of that.

17
Hi!

This is my first post; I've just gotten started for REAL doing demo stuff in Windows, and I'm building a little framework for handling "the basics", like opening windows, get mp3 playing in background, syncing audio and visuals etc, using BASS and DX9.

I have a specific texture that I use for "manual drawing", i e reading/writing bytes as if it were a buffer in a DOS demo (I wish).

The actual question: Right now, I'm clearing this buffer with just a for() loop, writing DWORDs with the default values (which are often just 0x00000000, but sometimes I'll default the alpha value to something else, depending on the effect). Surely there must be a way to have the hardware do this via DirectX?

I *am* already using something similar for clearing my backbuffer, but the DX documentation leaves me with more questions than it answers, and as far as I can see, I *might* be able to just set my texture as RenderTarget and do it that way, but device->Clear() also has stencil buffer and z buffer stuff, and it all just gives me a headache.

Is there a simple(r) way?


Thanks in advance,

XiA

18
General chat / Re: The Welcoming Comittee
« on: March 08, 2011 »
Hi!

I'm Per, I mainly code asm on Atari STE's under the project name "Excellence in Art", but I've dabbled in asm on Spectravideo's, C64's and DOS machines as well. Oh, and a little C on GameBoy Color. When I get enough free time (which seems highly unlikely at the moment) I'll finally finish my DX9 framework and hopefully do some C++ stuff for Windows.

Pages: [1]