#### Archived

This topic is now archived and is closed to further replies.

# What's the easiest way to draw a picture...

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

## Recommended Posts

to the screen using diectX9? Should I use a texture and trasformed vertices? Or is there an even easier way? Maybe getting the surface directly and just writing my data? I''ve been trying to mess with surfaces and stuff to get this to work, and im about to pull myhair out. Can someone point me in thje right direction?

##### Share on other sites
I had a similar issue due to "how" i wanted it displayed.

You can use sprites, surfaces, or what I ended up doing(as my picture NEVER changed size or anything), using Transformed Vertices and it worked perfectly.

I don't always do that but in this case it was for a console that was having text placed on it after it was drawn and I didn't need it to be changed.

1. Remember that before you go to draw with transformed vertices(if you are using viewports) to restore the original, as it wants to draw based on the size of the window, not the size of the viewport(found this out the hardware).

2. I used 4 vertices and a trianglestrip. Starting with bottom left, Top left, bottom right, top right coordinates and those are based on the screen.
(so for a 600(high) 800(wide) window to cover it all

Dim a(3) as vector3

a(0) = new vector3(0.0F,600.0F,0.0F)
a(1) = new vector3(0.0F,0.0F,0.0F)
a(1) = new vector3(800.0F,600.0F,0.0F)
a(1) = new vector3(800.0F,0.0F,0.0F)

3. Then map the Tu/Tv coordinates to these coordinates by doing this

u = ( Tx + 0.5f ) / textureWidth
v = ( Ty + 0.5f ) / textureHeight

for each vector use the same formula (where tx and ty = the screen coordinate you want, so 600 or 800 or 0)

I use a transformedTexture format

I set the camera position and lookat information
and the projection matrix and for world matrix I have a 0.0,0.0,0.0 vector

only thing you have to make sure of is, that your camera is somewhere "before" the Z value of your vectors, and your "far clip plane" is set to something after your vectors or else you wont see anything

Hope that helps.

[edited by - 3dxd on June 7, 2004 6:43:31 PM]

##### Share on other sites
ID3DXSprite is probably the simplest, although not the most efficient (but it is much much faster in the newest sdk).

##### Share on other sites
I did this and im getting a white block... and I cant seem to get the texture to display.

OOOOHHH... sprites...

Can you provide a small example? I could always read... but I been screing around all day! And I really want to finish.

[edited by - Matsy on June 7, 2004 7:32:42 PM]

##### Share on other sites
If you are getting a white block then you either haven't set the Textures Coords right, the camera start/lookat, or you have set your near clip to say 5 and your far clip to say 100 and you have to remember that your Z screen coordinate is 0.

If you put the camera at 0 and if your world coordinate was 0,0,0 then that means that you are not rendering the texture/quad because you have stated to start rendering 5 units past where your have your texture/image sitting.

The other possibility is that you didn't actually load the texture and you didn't catch the error.

Walk the code.
Show me your Projection Settings, Camera lookat, position, up vectors

as well as verify that the image is getting loaded.

its something in there.

Dont forget to actually set the texture when rendering or you get a white block(on the device).

I was going to mention too, be patient, jumping around without learning one technique, isn't going to make "sprites", which aren't really "easier", better or easier to use.

[edited by - 3dxd on June 7, 2004 7:40:06 PM]

##### Share on other sites
Cool thank you... I want to draw something now... I dont even want to reuse it. What I''m trying to do is generate noise. I''ve filled an array with my data. But now i just want to display it to the screen, and it''s a nightmare!!! Should I just use DirectDraw in Direct Show?

or maybe even windows GDI....

##### Share on other sites
Problem is, you still haven''t listed your code and your just "saying" it doesn''t work. Since we don''t know what your not doing right, its hard to tell you what to use.

Using directx to display a simple bitmap is easy but at this point its hard to help you without seeing the code your using so we can tell you whats wrong.

##### Share on other sites
quote:
Original post by 3DXD
If you put the camera at 0 and if your world coordinate was 0,0,0 then that means that you are not rendering the texture/quad because you have stated to start rendering 5 units past where your have your texture/image sitting.

Walk the code.
Show me your Projection Settings, Camera lookat, position, up vectors

If you''re using Transformed Vertices the camera and other matrices don''t matter since those vertices are already transformed.

Stay Casual,

Ken
Drunken Hyena

##### Share on other sites
So this MAY not be the problem, but certain graphics formats (TIFF, for example) just aren''t supported by DirectX natively. So what do you get when you load them? A white block.

Try converting your graphic to a .DDS file, and see if that makes a difference.

##### Share on other sites
Im loading an unsigned char array from memory... with random 0-255. in each slot.

quote:

Problem is, you still haven''t listed your code and your just "saying" it doesn''t work.

All my calls are working.... I''ve tried many things. How about someone show an example that works. Instead of me showing a broken example. Save lots of time. And others can use it for reference!

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 14
• 14
• 9
• ### Forum Statistics

• Total Topics
633368
• Total Posts
3011537
• ### Who's Online (See full list)

There are no registered users currently online

×