Archived

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

lacsap

Drawing lines in DX7

Recommended Posts

I have a question... I''m trying to write a GUI in DirectX, and the program is already able to load and display images, but i want to draw windows. The best solution for this is defining the width and height, and then draw the window, but HOW do you draw lines in DX7? I don''t know if this is already explained, but can someone help me with this..?

Share this post


Link to post
Share on other sites
G''day!

If you''re using DX7, then you can use GDI to do your line drawing. It''s not lightning fast, but it''s probably fast enough for a GUI. A DDSURFACE has a GetDC (or something like that) method that hands you a DC that you can use with GDI. Just remember to free the DC when you''re done.


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
i don''t know if this will help but its what i use to draw horizontal lines and it works good for me

void DRAWING::HorLine( USHORT *buffer, int pitch, int x1, int x2, int y, int color)
{
if( x1 > x2)
{
x1 ^= x2;
x2 ^= x1;
x1 ^= x2;
}

if( x1 < 0) x1 = 1;
if( x2 > 640) x2 = 640;

int lenght;
lenght = x2 - x1;

for(int x = x1; x < x2; x++)
buffer[y*pitch+x] = color;

}

Share this post


Link to post
Share on other sites
why dont ppl spend anymore time actually going through the sdk samples, or read the books they purchase?
its all "got code/where can download some/any good tutorials? " then you point them to a tutorial which explains the theory and they complain about no code. or the best one "Could any one get me some code, cause i can do it but i am too lazy to"

why dont you actually search for information? you spend all of 10 mins and get stuck and think that ppl are supposed to just give you all the answers. you dont know if it has been explained? try using the search system they have on this forum, or using google.

just a rant since, it amazes how many ppl fail to bother searching for answers anymore. i think the major problem is ppl dont learn anything, they are just mimicing things. with no understanding of the code and the theory behind the code you will get nowhere. its funny (well to me anyway) how ppl will see and learn how to do 2d stuff in dos in assmeblly even, but cant comprehend how to use dx AFTER getting it all initiliazed. ppl see how effects are done in opengl but cant tranfer the idea and algorithm to d3d or vice versa with an effect done in d3d.

one final note (btw none of this is not directed solely at you lacsap, your just the straw so to speak). dont ever suggest using the gdi in a directx app. its wrong, slow, and very clumsy solution to ANY graphical dilemas that may be faced. if you want to use the gdi, dont use directx. this include using the gdi to draw lines, shapes, text (probally the only exception if its solely for debugging), pixel depth conversion, bitmap loading, etc.

thank you for taking the time to read my rant. i know this should probally be in another thread, but would lose impact.



Edited by - a person on December 16, 2001 1:34:43 AM

Share this post


Link to post
Share on other sites
quote:
Original post by a person
dont ever suggest using the gdi in a directx app. its wrong, slow, and very clumsy solution to ANY graphical dilemas that may be faced. if you want to use the gdi, dont use directx. this include using the gdi to draw lines, shapes, text (probally the only exception if its solely for debugging), pixel depth conversion, bitmap loading, etc.


G''day!

That''s a load of crap. If you need line drawing, and it''s in a place where the speed isn''t much of an issue, why would you not use simple routines that are already provided? There is nothing ''wrong'' about using GDI with DirectDraw.

DirectDraw doesn''t draw lines, shapes, text, or load bitmaps. Windows provides an API that does, GDI. Yes, it''s slow, it''s also very flexible. ''Clumsy''? Well, that''s a personal opinion.

The GDI routines can be very handy. CD3DFont uses them, so does ID3DXFont. Both are provided by Microsoft''s DirectX team in DX8. So how wrong can they be?



Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
To combine the two previous posts:

It''s OK to use the GDI, but understand that it is very slow, so limit your usage as much as possible and/or limit it to initialization functions. For instance, I''d side with "a person" if you''re talking about drawing new lines every single frame. However, Ken refers to CD3DFont, which uses GDI at the start of the app and never again.

If you are creating windows, is it possible to draw all your lines to a surface once at startup (after the window has been defined) and then reuse the surface repeatedly without reusing the GDI?

Another nonGDI option... If you are talking about boxes such as the black border around an edit box, you could draw one black rectangle and then a slightly smaller white rectangle. The result is four black "lines" around your edit box. Maybe this would work for other windows as well.

Share this post


Link to post
Share on other sites
Lock the surface and draw the line (!?) What's so hard about that. Or you can use the GDI function, but I have experianced some problems with that using WinXP and it's slower

Here's the function we used in HemoHes World Championshit 2001
(http://hemohes.4t.com)
    


WorkSurface::DrawLine(int x1, int y1, int x2, int y2)
{
float difference_x;
float difference_y;
float line;
int i;

difference_x=float(x2-x1);
difference_y=float(y2-y1);
line=difference_y/difference_x;

Lock(NULL);

if(fabs(difference_x)>fabs(difference_y))
{
if(difference_x>0)
{
for(i=0;i<difference_x;i++)
{
if(i+x1>0 && i+x1< SCREENX&& i*line+y1>0 && i*line+y1<SCREENY)
{
Plot(i+x1,i*line+y1,0);
}
}
}
else
{
for(i=difference_x;i<0;i++)
{
if(i+x1>0 && i+x1< SCREENX&& i*line+y1>0 && i*line+y1<SCREENY)
{
Plot(i+x1,i*line+y1,0);
}
}
}



}
else
{
if(difference_y>0)
{
for(i=0;i<difference_y;i++)
{
if(i/line+x1>0 && i/line+x1< SCREENX&& i+y1>0 && i+y1<SCREENY)
{
Plot(i/line+x1,i+y1,0);
}
}
}
else
{
for(i=difference_y;i<0;i++)
{
if(i/line+x1>0 && i/line+x1< SCREENX&& i+y1>0 && i+y1<SCREENY)
{
Plot(i/line+x1,i+y1,0);
}
}

}
}

Unlock();
}



This function used my Lock() & Plot() function, so you have to write those to use it.

/MindWipe


"If it doesn't fit, force it; if it breaks, it needed replacement anyway."

Edited by - MindWipe on December 16, 2001 8:05:00 AM

Share this post


Link to post
Share on other sites
Two comments:

About making a GUI and drawing lines: If you''re interested in a shortcut, I have written my own headers, one for drawing basic shapes in DDraw (lines, boxes, squares, and putting patterns in them) and using it, I''ve also created my own GUI. If you are interested, IM me at ImmigrantMarbles on AIM or AOL (I would MUCH MUCH rather you do this than EMail me) or if you must, EMail me at VChelaru@hotmail.com.

About learning (quote by a person):
Interesting that you say people don''t learn, but here''s my take on it. If you''re making a game in DX, the point is to MAKE A GAME. When it comes to programming games, there is a lot of stuff that almost every game has: Your basic set up of all the DDRAW (or D3D) stuff. Some functions to take care of input from the user''s input and, as in this case, a GUI. The fact is that for a lot of people (myself included) making this stuff that other people have done is just a waste of time. Programmer''s time would be much better spent if these basic game skeletons were available easily and the programmer could focus on the important parts of a game.
Sure, I learned a bit making my GUI, but if I needed to, I would have learned that stuff at another time when it was necessary. Just my thoughts

--Vic--

Share this post


Link to post
Share on other sites