Archived

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

FlorianapoliS

How to draw a square?

Recommended Posts

Hi, I''ve been inspired by playing some old games to try and make my own. I have a good grounding in the basics of C++ eg. Variables, Functions etc... I went looking for tutorials on how to just draw something on the screen like a square of a box etc but I couldn''t find just a simple one. All I really need is a source code, so if you want to post how to do it, here is the place Thanks for your Time

Share this post


Link to post
Share on other sites
I think the best answer is learn DirectDraw, if you want source code, try the Articles & Resources section. Or if you want to stay in DOS, try the Asphyxia tutorials.

Share this post


Link to post
Share on other sites
To draw a square

create function for drawing verticle and horizontal lines
Here are some header examples
CreateVLine(int x, int y, int y1);
CreateHLine(int x, int y, int x1);

and then just connect the lines =)


Share this post


Link to post
Share on other sites
A rectangle, or any rectanglar prism can be defined by 2 poitnt. therefore, draw a vert line strait up from the first point to the y value of the second point then from there to the x value of the second point leaving y to remain 0. Do the same from the second point to the first point. Thats the basic algorithm, oh if you want the square to be filled, simply draw a h_line from each left point to each right point to fill the polygons.

Reality Makes Me XIC
I don''t do spelling, I hack code: passion is my feul. Use my programs, experience genius.
http://www.x-i-c.com/

Share this post


Link to post
Share on other sites
Yea, I know how it feels. Less than a year ago, I was in the same situation. Then I came across the DirectDraw tutorials on my MSDN CD, and after a couple of weeks of studying and copying them, I was on my way to making a game (well, kinda). Just read, copy, read, copy, compile, try to figure out why it doesn''t work when you made an exact copy, ask people what''s wrong with you, do what they say, repeat^_^
One thing you should be sure to do is (this is how to do it with MSVC++) Click on the Project menu, go to settings, click the Link tab, and in the objects/modules box, add ddraw.lib and dxguid.lib to the list. That was one of my first problems, and the examples seem to use a weird setup so you can''t see how they did it.

Oh, and hang around the DirectX board here and read other newbie posts. If you have a problem, most likely somebody else has had the same one. And don''t be afraid to post if you can''t find a solution. You might not get too friendly of a response sometimes, but the people there usually will help.

And one more thing, see that "for beginners" link under resources at the top of this page? Click that^^



-Deku-chan

DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)

Share this post


Link to post
Share on other sites
FlorianapoliS, if you can make lines, then JmarsKoder described it well. If you can plot pixels and don''t know how to make lines, then do a search on the Bresenham line algorithm. If you don''t know how to draw anything on the screen, then I would recommend buying a book on DirectX or OpenGL. Tricks of the Windows Game Programming Gurus would be a good one for DirectX. Of course, you could still stick with DOS and do graphics and stuff, but DirectX is a whole lot easier and better. And don''t listen to DekuTree64, copying and pasting lines of code of the MSDN documentation is not a very good way to learn anything.

Share this post


Link to post
Share on other sites
Actually, I was copying by hand, typing everything myself to get the feel of it, but a book might be a better idea. I didn''t have one, or know of any good ones, so the tutorials were the best I could find at the time.



-Deku-chan

DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)

Share this post


Link to post
Share on other sites
Thanks for all your help!

I''ve downloaded Allegro and I learnt how to draw a square, now I''m going to try and learn how to do it in DirectX, or maybe OpenGL but I heard that is a bit harder. I''m not sure if thats true so I''m going to try both.

I''m also going to go looking for some books to set me in the right direction

Thanks again for all your help.

Share this post


Link to post
Share on other sites
hmmm im still in the early stages of development of my programming skills (just over 18 months since i typed my first line of Ada code - with Ada.Text_IO, and i find that copying direct from a book is counterproductive. When i cover a new topic/chapter, i create a program based on the new material, but a completely different subject matter, so i *cannot* copy verbatim, and afterwards, i know that ive learned it.

i dunno about with other people, but when i used to do it that way (copying from text book), when it came time to implement one of my own, using those techniques, i had to keep referring to the copied program, cos just copying code doesnt fully make it sink in - at least not with me

here in castle camelot we eat ham and jam and spam alot!

Share this post


Link to post
Share on other sites