Sprite vs Vertices

Started by
9 comments, last by TomKQT 13 years, 1 month ago
I was curious, I have two ways to display a 2D image on the screen, using D3DXSPRITE or by drawing a textured quad. I am not sure as to which would be better for creating a movable viewport (camera). Basically, say I have an area that is 5000x5000 and I can only see 800x600 at a time. Everything being rendered is same position, but the viewport is what moves around the area. Which is better? Also can I get a few pointers as to what I would need to create this kind of viewport. Thank you in advance.
Advertisement
Nothing quite yet, I have been looking into D3DXMatrixOrthoLH(...) would that be a step in the right direction? Or would that only benefit for using vertices?
Does no one know how to make a 2D camera using DirectX? I thought I would get quite a few responses but I got absolutely none! I have Googled this subject over and over and tried many different examples and nothing acts like a moveable 2D camera or even a moveable 3D camera for that matter, everyone just moves the objects instead, which if your game is big enough would cause major lag in the end because everything offscreen would have to move too, am I wrong?
If you only want to move the camera I would use positioned textured quads, since the Sprite class uses transformed screen coordinates (someone correct me if I'm wrong).

About the last post, you wouldn't need to render objects (or care for them at all) that are completely outside of the viewport.
That is my point, having a camera that can move would eliminate dealing with outside objects that are not within viewport ranges. Here is the issue, I can't seem to find an actual piece of material online that talks about making an actual camera viewport to move around to save my life, if they discuss it it is very vague and technical nothing to do with DirectX, or it is showing examples of DirectX but it is pieced together from some previous 10 tutorials and I honestly don't want to go through the 10 tutorials of stuff I already know how to do like draw a quad or triangle, just to see when they added a viewmatrix or something similar (you can draw a quad without that crap so I wish they would stick to the points). Any suggestions would be great I have honestly been messing with this for 3 days now and coming up short everytime. To anyone who can help these are my requirements.

2D Camera (viewport)
using textured quads
Moves along the x and y coordinates

When I move, my textured quad stays in it's relative coordinate position so if I move the camera away it will eventually go offscreen.
don't want to go through the 10 tutorials of stuff I already know how to do like draw a quad or triangle, just to see when they added a viewmatrix or something similar (you can draw a quad without that crap so I wish they would stick to the points


Sorry but you're going to have to look at that crap if you want a camera because that's how cameras work. The answer to any "how do I create a camera?" question is going to be: set your view matrix, set your projection matrix, set your world matrix, draw stuff.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Ok this is what I got for setting up the camera, how can I move it. Would I have to change eye and than call it all again? and what is world doing exactly because it doesn't appear to be doing anything really. I didn't mean to sound like I wanted an easy fix, I just didn't want to have to go through someone else's code in 10 tutorials to find when and where they implement something I needed. It is hard to tell if you setup a camera correctly considering nothing changes at first. I am staring at the same quad or I am staring at a blank window...


D3DXMATRIXA16 world;
d3ddev->SetTransform(D3DTS_WORLD, &world);

D3DXVECTOR3 eye(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 look(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMATRIXA16 view;
D3DXMatrixLookAtLH(&view, &eye, &look, &up);
d3ddev->SetTransform(D3DTS_VIEW, &view);

D3DXMATRIXA16 proj;
D3DXMatrixOrthoLH(&proj, WIDTH, HEIGHT, 0.0f, 1.0f);
d3ddev->SetTransform(D3DTS_PROJECTION, &proj);
This being 2D I wouldn't use the LookAt function for the viewMatrix. Why not a regular translate matrix(for camera movement) multiplied with a scale matrix (for zoom) for the viewMatrix?
it doesn't appear to be doing anything really


What is your vertex declaration or FVF for the quads? Doesn't it contain D3DFVF_XYZRHW? If yes, then any transformation matrices set by d3ddev->SetTransform() won't affect the quad drawing anyhow, because with D3DFVF_XYZRHW you are specifying positions in "screen" coordinates, that means already "transformed" and D3D won't transform the vertices anymore.
But I'm just speculating, so - what's your FVF so that we can talk about your real situation?
Yes my FVF is set to D3DFVF_XYZRHW | D3DFVF_TEX1...

This topic is closed to new replies.

Advertisement