Jump to content
  • Advertisement

Archived

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

Cinnamon

How to draw a line, a rectangle and a circle with C?

This topic is 5764 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 would like to have some codes to know how to draw a line, a rectangle (or square) and a circle with C. Or maybe you have other stuff like that to show me? Most of books don''t teach these things. Thank you!!! Eric Chambers www.cinnamonmagazine.com

Share this post


Link to post
Share on other sites
Advertisement
Yes, most general programming books wouldn''t teach those concepts and most graphics library packages provide prebuilt functions that will do the work for you - GDI, DX, OGL, SDL and so on.

The subject isn''t as simple as drawing a line or circle on paper
Check out the tutorials here. Also check out flipcode and gametutorials.com. Also Google on "Breshenham" - hhh.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Displaying graphics in C is not as simple as it is in other languages that may have built-in functions to draw lines, circles, etc. C has no concept of a "line" or a "circle" or even a video card. All you can do in C is read and write values to memory locations. If you write some value to a memory location that happens to be on the video card (in a special area called the frame buffer) then what you get is a pixel on the screen. Putting one pixel on the screen is simple enough, drawing lines and circles requires a little math. You could write your own pixel plotting functions, but there are libraries already written that give you access to the display. LessBread mentioned a few. DirectX is a good one if you are developing on a Windows machine. Since you posted this in the Beginners forum, please give us some indication of your confort level with C, that way people will know whether to tell you to look into a graphics API or to get more familiar with the language before moving on to graphics. Good luck and don''t get discouraged!

Share this post


Link to post
Share on other sites
quote:
Original post by granat
DX has built in line support ????? Sure ?



Not explicitly - but it does provide for other primatives - box, cynlinder, sphere, torus. I was speaking generally - The AP explained it better than I did.

Share this post


Link to post
Share on other sites
I''m really a beginner. I started programmation 3 days ago, but I learned it for about more than 10 hours by days. So, I have around 30 hrs of experiences. But I think I''m learning fast. Things are getting clearer now.

I did a lot of Basic 7 years ago, and I did a little battle scene like Final Fantasy with a lot of cool effect. I''m tring to do the same thing with C now.

If C is not compatible with graphical stuff, how did they make games like Final Fantasy on the Super Nintendo?



Share this post


Link to post
Share on other sites
quote:
Original post by Cinnamon
If C is not compatible with graphical stuff, how did they make games like Final Fantasy on the Super Nintendo?



Don''t forget Quake and Quake II - It''s not a matter of "compatibility" - it''s that the language itself doesn''t specify any requirements regarding a large range of familiar computer hardware components. That makes the language very flexible. Instead what you get is a buffer of memory - that could mean a file, an array, or a video buffer. What you do with that buffer is up to you. Like the AP said - "All you can do in C is read and write values to memory locations." That might sound limited - but really that''s all you can do in any programming language - it''s just that most other languages do all that for you "underneath the hood" so to speak. All the math and such is preprogrammed and what you''re left with is calling a function that does the work - like DrawCircle or what have you. The libraries I mentioned do that too. As you continue forward with your studies this will become more clear to you.

Share this post


Link to post
Share on other sites
I will do plenty of search and try to improve my learning with C. Anyway, it will be a good thing to be part of this forum.

Share this post


Link to post
Share on other sites
once you feel comfortable writing simple non graphics programs in C, try SDL/DX or OpenGL (which ever you find easier) and then you can draw stuff and write simple games.

Share this post


Link to post
Share on other sites
I don''t quite understand what are SDL/DX or OpenGL. Are they different language?? can I use then with text files and compile them with Visual C ++ 6.0?

It is easy to print a single pixel on the screen with C source???

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!