Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 10 Nov 2008
Offline Last Active Sep 25 2013 12:25 PM

Topics I've Started

Problem with orthographic projection

22 September 2013 - 08:39 PM

So I'm looking into doing some 2D graphics with Direct3D 11. I am having a problem getting a simple orthographic projection to work right, and I am hoping that somebody can tell me what I may be doing wrong, or ideas of how to figure it out.


My vertex layout is a simple position/color layout, and the vertices are these:


        {0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f},
        {1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
        {-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f}


This is my vertex shader:

cbuffer cbChangesPerFrame : register( b0 )
    matrix worldMatrix;
    matrix viewMatrix;
    matrix projectionMatrix;

struct VS_Input
    float4 pos   : POSITION;
     float4 color : COLOR;

struct VS_Output
    float4 pos   : SV_POSITION;
    float4 color : COLOR;

VS_Output main( VS_Input vertex )
    VS_Output vsOut = (VS_Output)0;
    vsOut.pos = mul(vertex.pos, worldMatrix);
    vsOut.pos = mul(vsOut.pos, viewMatrix);
    vsOut.pos = mul(vsOut.pos, projectionMatrix);
    vsOut.color = vertex.color;

    return vsOut;

And this is my code to setup the constant buffer:

    XMMATRIX all[3];
    all[0] = XMMatrixIdentity();
    all[1] = XMMatrixIdentity();
    all[2] = XMMatrixOrthographicOffCenterLH( 0.0f, 600.0f, 0.0f, 400.0f, 0.1f, 100.0f );

    ctx->UpdateSubresource( _constants, 0, 0, all, sizeof(XMMATRIX) * 3, 0 );
    ctx->VSSetConstantBuffers( 0, 1, &_constants );

This results in a red single-pixel line being drawn from the top center of the screen, to about the center of the screen.


If I change my matrices to the following:

    XMMATRIX all[3];
    all[0] = XMMatrixIdentity();    
    all[1] = XMMatrixIdentity();
    all[2] = XMMatrixIdentity();

Then the triangle renders as I expect; with one point at the top center, and the other 2 points at the bottom corners, with a red-green-blue gradient. So it would appear that the vertices are being correctly pushed to the shaders.


I have tried explicitly setting the .w position value to 1 in the vertex shader, I have tried using 4-element position values in the code, I have tried using a single matrix in the shader and multiplying them in code, and I have tried using a single matrix in the shader and just setting it to the projection matrix, all of which I figure should be the same since I'm using identity for the other 2 matrices anyway, and of course the result is the same in all cases.


What could I be missing here?



Lossless RGBA video compression or other way to process pre-rendered animations

09 June 2012 - 02:53 AM

So I've got a 2D game that needs to run some large (close to full screen) pre-rendered animations on top of the game graphics periodically.

Currently I just have them as a series of PNG images that are loaded and decompressed when the level is loaded, and then when we need to render them we just flip through the images. This works, but it is far from ideal for our application; we are targeting embedded systems with embedded Intel graphics adapters, relatively slow memory buses and Compact Flash drives, so both the load times and runtime performance is a bit prohibitive for our platform. i.e. a 1024x1024 RGBA animation with 100 frames requires over 400MB of memory, and we have to blit 120+MB per second to achieve 30fps just for the animation, plus it takes 15-20 seconds to load the PNGs from the CF drive and decompress them.

The animations are not dramatic, so I think they would work well with a lossless video compression of some sort. There is not a whole lot of change from frame to frame, and we have plenty of CPU cycles to spare. I have looked at a few codecs like HuffYUV, but the ones I've seen only really seem to work with RGB or YCbCr.

Does anybody know of any RGBA lossless video compression (preferably with a free or inexpensive cross-platform library support)? Or know of another way to accomplish this?

Generating good UV coordinates

23 December 2008 - 01:49 PM

Hi all, I'm currently in the process of developing a level editor for a game that I'm developing. I've got a pretty good start, but there is something I would like some input on. I am highly interested in any input or resources on generating good UV coordinates for convex hulls. For starters I'd love to be able to duplicate the "Box" UV mapping that can be done in 3D Studio Max on arbitrary meshes. Or something similar to what applications like 3D World Studio do to produce uniform texturing. I've seen some material that gives some mathematical formulas, but I'm unsure of what some of the inputs represent or how to find them, i.e. UV offsets, texture axis, etc. Any help on this would be great. Thanks