Where to do graphics

This is a discussion on Where to do graphics within the C++ Programming forums, part of the General Programming Boards category; Hi guys, I want to display very simple lines and shapes like circles. How do i do this and what ...

  1. #1
    Registered User bobbinator's Avatar
    Join Date
    Jul 2009
    Posts
    29

    Where to do graphics

    Hi guys,
    I want to display very simple lines and shapes like circles. How do i do this and what should i use (the easiest would be the best )

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    You need to use a graphics library to do this. Some popular ones are Direct3D (Windows only), OpenGL, QT, or SDL.

    Which one is "easiest" is probably subjective, but I've heard good things about SDL. I've used QT which was pretty easy, and OpenGL which was a little harder.

    Are you looking to eventually create games and 3D environments? If so, then QT and other Windowing toolkits are not what you are looking for. In this case, you want to use SDL, OpenGL, or Direct3D.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User bobbinator's Avatar
    Join Date
    Jul 2009
    Posts
    29
    No
    I just want to display a box and a circle inside it

  4. #4
    i've lost my mind
    Join Date
    Jun 2008
    Posts
    26
    If you don't tell us what you're overall goal is, or what you intend to work towards, then it's hard to make suggestions. Why? Because different approaches offer differences in ease of use vs flexibility and control.

    Since you're going to be vague I'll just suggest the extremes.

    OpenGL or DirectX.

    The differences between them come to style and crossplatform across multiple OS's or crossplatform across Windows operating systems.

    Or the easiest method, open up a .Net project in a free version of Visual Studio and paint to the form control with a few simple methods - worst performance, idiotically simple.
    Last edited by gltiich; 09-08-2009 at 10:56 AM.

  5. #5
    Registered User bobbinator's Avatar
    Join Date
    Jul 2009
    Posts
    29
    That sounds good!

    Ok, this is linked to my particle simulator. I know all the math behind this project such as projectories, energy lost after each collision and stuff. I just want the easiest way of display very basic graphics such as lines and circles. All 2D, thats it!

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    Quote Originally Posted by gltiich View Post
    Or the easiest method, open up a .Net project in a free version of Visual Studio and paint to the form control with a few simple methods - worst performance, idiotically simple.
    And what are exactly the performance requirements of drawing a circle inside a square? As for "idiotically simple", that just convinced me to go .Net.

    Anyways, to draw 2D with C++ we need to know where (Windows, Linux, Macintosh,...). But applicable to all these three you can either go with a GUI framework API such as wxWidgets that besides giving you the ability to code for the operating system GUI (Windows, Gnome, OS X) also includes the necessary API call wrappers for 2D drawing on windows. Or go with a specific library like SDL.

    Non portable solutions are those involving calls to the operating system GUI API. On windows you would use the Win32 API.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    Sounds like you are actually looking for a graphing library.

    This looks like a good place to start.
    bit∙hub [bit-huhb] n. A source and destination for information.

  8. #8
    i've lost my mind
    Join Date
    Jun 2008
    Posts
    26
    I can tell you from experience, especially in designing particle systems, that you'll want access to hardware accelleration for good response time / framerates. Just because your graphics are 'just 2d' doesn't mean squat. I can give you some source code right now for something that's 'just 2d' which will render 1 frame per second and look like crap.

    Whether you're drawing 2d or 3d is irrelevant, both dimensions of space can be used to express complex or simple models.

    What matters is your models, how complex they are, and how you want them rendered. Do you just want to render a static image of a scene or real-time rendering? You could easily go with a .net drawing control if all you want is a single snapshot of a specific time in a system.

    OR

    Do you want to watch your particle system render over many intervals of time? How many frames per second? Given a certain level of mathematical complexity it might be that you can only practically reach 30fps+ on the CPU, and to surpass that you would need to write GPU shaders for 'just 2d graphics.'

    You can work with libraries that only do software rendering which will cap your FPS potential, given a certain level of complexity, to the CPU's ability to calculate results for your equations. To surpass that level of performance for said level of complexity you will have to involve some level of hardware accelleration by the GPU (OpenGL/DirectX), and at the end of the road you could actually write your own GPU Shaders (GLSL/HLSL/etc) - or incorporate a physics card to help remove some load off of the CPU.

    So as you can see, wanting to do 'just simple 2d' is an understatement. What does not matter is if you want to do 2d or 3d, what does matter is the complexity of your systems on which your drawing is *based and the performance requirements.

    So, I hope this clarifies how to decide what to use and why, it ultimately comes down to performance. Do you want a 1FPS circle and square? or 600fps circle and square? or an on-demand single instance drawing of a circle and square (like user interfaces or something, they only redraw on events)? ;]
    Last edited by gltiich; 09-08-2009 at 01:13 PM.

  9. #9
    Registered User bobbinator's Avatar
    Join Date
    Jul 2009
    Posts
    29
    I love you gltiich
    That is one HELL of a response.

    Ok yes, its real time so things are moving about. So far its not complex and i would like around 30 fps. I can see what you mean now with the understatement.

    Are there any graphic tutorials and if so, links would be much apreciated!!!

    Thanks for ALL the help guys (so far ) Hopefully this will get me into oxford university!

  10. #10
    Registered User bobbinator's Avatar
    Join Date
    Jul 2009
    Posts
    29
    Ok, I cant install any libraries because they just dont want to install. Im using Code Blocks and every time i try to install Allegro it WONT WORK. Why cant people just make exe self installers!

    I need help installing these libs!!!

  11. #11
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    Libraries have lots of documentation. On their websites and within the archives containing the source code. Instructions for building and basic usage are in any of these places or on both.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  12. #12
    Registered User bobbinator's Avatar
    Join Date
    Jul 2009
    Posts
    29
    Im getting annoyed now because I followed the Allegro instructions to the letter, it did not work!

    ALL I WANT IS A CIRCLE INSIDE A SQUARE. Code Blocks is irriating, Visual C++ Does not work with the win32 window for some reason, and Dev C++ wont even let me install the allegro package!!!

    My god its so hard, so i am going to do something like an SDL project. Does anyone know of good SDL tutorials?

  13. #13
    i've lost my mind
    Join Date
    Jun 2008
    Posts
    26
    Well, I've mostly used GLUT for OpenGL applications, there's only one thing required to get that to function which is to append the below snippet in to your source *before the actual glut include.

    Code:
    // ... required for Glut
    #ifndef _STDCALL_SUPPORTED
    	#define _STDCALL_SUPPORTED
    #endif
    // ... you may also need to define D_M_IX86
    Various libraries may have other various requirements in order to properly function, you really have to dig in to it to figure out how to build your projects from scratch. The reason these things are not automated by default is because all systems out there vary quite a bit, the developers just want to build a library for you to use - getting it implemented for you to use however is up to you or some 'generous' IDE's. Lazy programmers! >;D (It's OK though, once you figure the stuff out it's no biggie.)

    I used to use Dev-C++ which offered "Dev Packs" for all sorts of project types related to OpenGL or anything else, these packs would let you create new projects with all necessary requirements included (very convenient). It's just that Dev-C++ can be a little quirky in general use unfortunately...

    The thing you don't want to hear though, but it's not as bad as you think it is when you really get in to it, is learning the API by the formal documentation provided by OpenGL and GLUT, etc. It's not as dry as it might seem, and usually they give examples of how the API is meant to be used as it's explained. But if I had to make a recommendation otherwise I would suggest starting with the famous Blue Book; http://www.opengl.org/documentation/blue_book/ It's free...

    There's also an Orange Book and Red Book, between them you can master OpenGL programming and have hardware accelerated graphics!

    DirectX has plenty of resources too but... I don't know, it always annoys the hell out of me for various reasons I won't go on about here. Besides, knowing OpenGL keeps you open to Linux or any other platforms out there. I just picked up iTouch/iPhone programming and guess what! OPENGL BABY, DAM RITE! RAWRz! >:]
    Last edited by gltiich; 09-09-2009 at 11:13 AM.

  14. #14
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by bobbinator View Post
    Visual C++ Does not work with the win32 window for some reason
    What does that actually mean?
    What's wrong with using VS2008 Express and ResEdit?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  15. #15
    i've lost my mind
    Join Date
    Jun 2008
    Posts
    26
    OOooo!!! It just occurred to me, I completely forgot about Processing.

    Processing 1.0

    If I remember right it's based on Java, but that language will be fine and even more intuitive for you to use than C++. Java and C# are very similar to C/C++ in structure but far more 'purely' OOP oriented.

    The site has fantastic tutorials which demonstrate how to use the language and implement all kinds of maths and give great visual output (It's built on OpenGL). From now on I might recommend people start with Processing since it's based on a cross-platform language, easier to pick up I'm sure for people just starting, and there's a large dedicated community behind it. :]

    Also, setting it up will be far easier then picking libraries together yourself, if you don't want to bother with all of that then I strongly suggest you take a look at Processing. ^_^ From that point it will be easier for you to move in to other languages and get deeper in if you choose to.

    Actually, their tutorials are good to go through for anyone new to graphics programming in general, with the desire to also improve in maths: http://processing.org/learning/


    And if you really don't want to go with Java you could look in to Actionscript through Macromedia flash. There's a little application out there called HAXE which will compile Actionscript and spit out an SWF. So you don't actually need the Macromedia studio at all! http://haxe.org/ - I use HAXE on a shell I have to do little quick and dirty tests of stuff and such, it's very handy.


    Sorry for all the edits, all this stuff just came back to me after I had some (late) lunch.
    Last edited by gltiich; 09-09-2009 at 03:20 PM.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Turtle Graphics, how does it work?
    By freddyvorhees in forum C++ Programming
    Replies: 15
    Last Post: 08-28-2009, 10:57 AM
  2. Graphics Programming :: Approach and Books
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 05-11-2004, 09:33 PM
  3. egavga.bgi problem
    By sunil21 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-22-2003, 06:06 PM
  4. Graphics Devices and Cprintf clash
    By etnies in forum C Programming
    Replies: 6
    Last Post: 05-09-2002, 12:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21