How to use graphics and sound in C?

In summary, the individual is looking for a way to write a C program that can output graphics and sound. They are currently using DevC++ and are interested in using GDI for 2D vector graphics on Windows. However, the expert recommends using a cross-platform graphics library such as OpenGL instead. They also suggest using a GUI toolkit like wx, Qt, or GTK+ for easier implementation. They further suggest using a platform like wxPython instead of C/C++ for a smoother experience.
  • #1
Lojzek
249
1
I would like to write a C program that outputs graphics and sound.
I use DevC++.

How can I do it?
 
Technology news on Phys.org
  • #2
Lojzek said:
I would like to write a C program that outputs graphics and sound.
I use DevC++.

How can I do it?

Well, what type of graphics? Aimed at what operating system? In windows, you can use GDI (graphics device interface) to do 2D vector graphics, and also use bitmaps. You might want to use a cross platform graphics library such as OpenGL to do your graphics if you want to port your application to other operating systems.
 
  • #3
computerex said:
Well, what type of graphics? Aimed at what operating system? In windows, you can use GDI (graphics device interface) to do 2D vector graphics, and also use bitmaps. You might want to use a cross platform graphics library such as OpenGL to do your graphics if you want to port your application to other operating systems.
I don't know anything about graphics types. I just want to find any way to put colored points on the screen on the specified coordinates calculated in C. I use windows. Can you tell me more about GDI? Is this a program that I can download? And how can I transfer information between C and GDI? I suppose data calculated in C must be put to a file in a specific format?
 
  • #4
GDI is the Windows graphics subsystem - it's the set of commands to draw a point/line etc in a window. There is also opengl, a more complicated but industry standard way of drawing 2d and 3d objects.
Look at http://www.codeproject.com/KB/GDI/ for samples of windows programming, I assume from the dev c++ you are on windows?.
 
  • #5
You cannot do these tasks directly from C/C++ alone -- you need to use some kind of a library. The GDI is an interface to Windows directly, and I advise that you do not use it. It's very cumbersome and, of course, locks you into using Windows.

Instead, I'd recommend that you take a look at the various cross-platform GUI toolkits and pick one that suits your needs best. wx, Qt, and GTK+ are all good choices.

Using these toolkits from C/C++ is by no means easy. You'll actually need to be a fairly sophisticated programmer to use them. As a result, I strongly recommend ditching C/C++ entirely, and using a platform like wxPython for your work.

- Warren
 

1. How do I include graphics and sound libraries in my C program?

To use graphics and sound in C, you will need to include the appropriate libraries in your program. For graphics, you can use the graphics.h library and for sound, you can use the sound.h library. These libraries can be downloaded online or included in your C compiler.

2. How can I draw basic shapes and images in my C program?

To draw basic shapes and images, you will need to use the functions provided by the graphics library. These functions include line(), circle(), rectangle(), and image(). These functions allow you to specify the coordinates, size, and color of the shape or image you want to draw.

3. How can I play audio files in my C program?

To play audio files in your C program, you will need to use the functions provided by the sound library. These functions include play(), pause(), and stop(). You will also need to specify the file name and location of the audio file you want to play.

4. Can I create animations using graphics and sound in C?

Yes, you can create animations using graphics and sound in C by using loops and changing the coordinates or properties of your shapes or images. You can also incorporate sound effects or music to enhance your animations.

5. Are there any limitations to using graphics and sound in C?

While using graphics and sound in C can provide basic functionality, there are limitations to what you can achieve compared to using more advanced programming languages or frameworks. For example, creating advanced graphics or playing high-quality audio may not be possible using only the basic libraries in C. It is important to understand the capabilities and limitations of your chosen programming language before starting a project.

Similar threads

  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
24
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
Replies
1
Views
952
  • Programming and Computer Science
Replies
9
Views
2K
  • Programming and Computer Science
Replies
11
Views
2K
Back
Top