Jump to content
  • Advertisement

Archived

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

Wayfarer

2D on 3D

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m moving some of my 2D drawing routines to use D3D IM, so I can take advantage of things like 3D hardware alpha-blending and such, and I would like to know how to draw rect and line primitives in 3D given screen coordinates only? For example, if I want a horizontal line to appear exactly at screen coords 100,150 to 200,150, how would I draw this in 3D? Does it matter how I setup my transformation matrices, projection, view, etc.?

Share this post


Link to post
Share on other sites
Advertisement
Hehehe bracket Must feel good to have so much response to your article!

#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**

Share this post


Link to post
Share on other sites
So if I use D3DTLVERTEX to put a rect or line primitive exactly on the
screen where I want, what are the members D3DVALUE rhw and D3DVALUE sz used for?
How do these two values affect the screen position of the primitive? Do I even
need to set these two when all I want is something that looks 2D?

Share this post


Link to post
Share on other sites
sz isn''t used for 2D coordinates - how could it be? I tend to leave rhw at 1.0f to ensure that textures plot properly, since we can''t calculate "1/z" in a meaningful manner. The point of D3D''s flexible vertex format is that you choose the stage of the transformation pipeline you want to interact with, and enter relevant data only.

MadKeith: yes, it feels great to be in demand, although the BIG downside to writing an article like that is the sheer volume of email I get asking the same questions!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

I got it working, but I''ve encountered some quirky situations:

Drawing a rect (as a trianglestrip) does plot the bottom and right
lines of the rect. But, I''ve kinda of suspected that somehow.

Drawing vertical and horizontal lines:
horz. line left-to-right = the last pixel is not drawn
horz. line right-to-left = the first pixel is not drawn

vert. line top-to-bottom = the first pixel is not drawn
vert. line bottom-to-top = the last pixel is not drawn

Is this how it should work?

Here''s how I setup my horizontal line:

D3DTLVERTEX HLine[2];
D3DVECTOR v = D3DVECTOR(0.0f, 0.0f, 0.0f);

HLine[0] = D3DTLVERTEX( v, 1.0f, 0x00ffffff, 0.0f, 0.0f, 0.0f );
HLine[1] = D3DTLVERTEX( v, 1.0f, 0x00ffffff, 0.0f, 0.0f, 0.0f );

HLine[0].sx = 100.0F;
HLine[0].sy = 150.0F;

HLine[1].sx = 200.0F;
HLine[1].sy = 150.0F;

And draw it:

d3d_device->DrawPrimitive( D3DPT_LINELIST, D3DFVF_TLVERTEX,
HLine, 2, 0 );

It does not plot pixel 200,150.

Share this post


Link to post
Share on other sites
Your last pixel isnt being drawn because the co-ordinates are inclusive-exclusive.

The first co-ord is included in the draw, but the last one is not, to get the last one to appear just increase your end co-ordinates by 1.

Share this post


Link to post
Share on other sites
Take care all
Ihave tested Enhanced2D on a P150/64M video S3DX/GX with 4Mb VRAM and it does very poor: 1,5 fps at maximum...

On the other side my 2D asm routines (wo lights )
does better every time from 10 to 20 fps (full screen with a 240x320 alpha surface and scroll and may other things)

so 3D is NO Solution for low end PC...but maybe u dont want that market (at least not in USA)
still remember that not every guy is upgradeing his PC every year and USA standards are not (yet) standards for the world....

On the other hand it does better on my P2/400/128M/Voodo3
(150 up to 200 fps) but i think its my Vooodo that helps a loooot... i will try it on other boards ....


Regards

Share this post


Link to post
Share on other sites
bogdanontanu: I tend to agree with you about performance on low-end PCs. Anything much below a P120 struggles with D3D rendering, although the most important factor seems to be graphics card fill rate. If you are lucky enough to have a card with decent triangle-fill rate (and ideally at least 2 Mb texture memory), you get pretty good framerates. I tested a P150 with a Voodoo 1 and achieved a 20-30 fps for an average isometric scene. OTOH, using a Matrox Millenium or the old NV1 chipset (whose triangle fillrates were abysmal), was too slow to be worth measuring. Still, nothing I write really targets much below a PII-233 Mhz. If an audience that "small" is good enough for EA, its good enough for me!

I do think that with a combination of well-structured code and appropriate use of assembler (ASM is wonderful, but there is no point optimizing code thats called infrequently!) you could probably come up with a software gouraud triangle shader that would give decent framerates on low-end pentiums. I mean, if Unreal can run on a Pentium 200 in software mode, it is possible! About a year ago I experimented with Allegro''s (using DJGPP for DOS) shaded triangle rendering to achieve similar results. I was thinking of optimizing this beyond the 5 fps I achieved, but I picked up Visual C++ and started actually using my neat hardware! :-)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!