What to use when drawing shapes in C? - c

I've been having some problems trying to figure out with header is useful to manage to get a screen, and draw shapes in it, using C.
Tried to use 'graphics.h' but is not working for me, I think maybe 'graphics.h' is meant to be used in C++ and not C? I really don't know and would appreciate it if someone knows anything.

On Linux, you can't build a graphical app using only stdlib. You have to add something like OpenGL, Xlib, maybe Qt or even SFML. Good luck to make an app)

I believe graphics.h is a Windows-specific library. Assuming you're on Linux, you can use gfx.
gfx is an xlib-based graphics library with some very basic functions to draw lines/pixels and get keyboard input. I wouldn't use it in a serious project, but it's fairly easy to get started with. You can even add functionality to draw more complex shapes if you mess with the source code and some XLib functions.
If that's too basic, you can use SDL2 for 2D graphics, OpenGL for 3D graphics, and ncurses for terminal-based graphics.

Related

Making a GUI without a framework in C

I'm learning C (I just finished Chapter 2 or Unit 2) of the C Programming Language, I skimmed to the end and saw that at no point anything was said about how to create a GUI, and from what I've looked up, it seems I have to use a framework, but I hate the idea of that. How would I create a GUI without a framework? How exactly do these frameworks work and what language are they written in? I'm not making a massive application, even if it takes me a week, would it be feasible to write a GUI application (in C) to do something simple like creating a window?
You can build your own framework based on OpenGL or Xlib. Or use good graphics library like Motif or CGUI. Or use something awful like GTK.
Not the best road to take. I would suggest a cross platform library, like GTK+.
Yeah, no go.
C can't do anything except manage memory and possibly do software interrupts (if you do pointer hacking).
You need a library to do anything.
GUI is very complex, you can't do anything "simple" with it. It's a problem I face every single day.
If you want a window in C, you need X11, GTK, Windows API, Video hacking, or other fun stuff.
Oh, and Video hacking is a no go, OS will throw an exception if you even try to touch video memory without its permission.
Oh, and the "simple button" you speak of, in Windows API is actually a Window itself, not very simple.
You can make a basic framework using the WINAPI
There is a great tutorial here.
The problem with using C and primitive frameworks like WINAPI is that manging layout and state becomes exceedingly difficult.
If you targeting a normal operating system, the C only requirement becomes unreasonable. I recommend you go with C++ and Qt and compile your C code in a C++ compiler.

Making a GUI simulator in C

Hello StackOverflow Community,
I am writing a MicroMouse Simulator in C language. And I wanted something to visualize the way the maze is being solved like this -- http://www.youtube.com/watch?v=N9TkDgJNJso
I've been researching a way to accomplish this, but I haven't found anything with enough documentation to accomplish my goal.
I don't want to implement this using ASCII symbols, to me it doesn't look professional.
Is there any good GUI interfaces that I could use in C to help me accomplish this? And if so, how would I use it? I don't mind having to code in another language like Java or Python to accomplish my goal.
I saw the video that you want to make. After watching the video I feel you don't need a GUI library for this simulator program.
Here is a list of libraries that you can use.
1.OpenGL This is a 3D graphics API which also can be used for 2D and can be used with both c/c++
2.SDL This library is easy to understand for a beginner. For your program this library is better and can be used with both c/c++.
3.winBGIm This is same as the graphics.h that you found and can be used both c/c++ but it is only for windows.
If you are looking for GUI library then here's a short list.
1.GTK This is written in c and is a popular GUI library for c. You can find a GUI editor for gtk forms called glade which enables quick & easy development of user interfaces.
2.WxWidgets This is written in c++ so you have to use c++ rather than c.
3.FLTK
There are many more libraries besides these which you can find in google. You said
I do not mind having to code in another language like Java or Python to accomplish my goal.
Then for java you can use swing and If you are windows developer then use the windows form application in visual c++; then development of your program will be very easy.
SDL is one of candidate for C in order to make GUI Simulation. Lazyfoo is one of the best site I found for beginner.
SDL is strongly portable. It's written in C and there're a lot of documentation and tutorials.

What is the easiest way to go with for simple drawing and event capturing in C?

I need to create a simple drawing program in c for graphs, i.e. nodes and lines, thus I would also need to capture events. I would need to run this in Linux and Windows ( though not a requisite for Windows for now). I haven't done any drawing in c before (a little opengl a long time ago), I am guessing my options would be gtk, sdl or opengl. What would be the easiest way to do this?
With those requirements, I'd go with GTK+. You will use Cairo for the primitive graphics, which is nice and easy.
And the events will be standard GUI events, so also easy.
GTK+ can have some learning curve, though... but certainly not more that OpenGL.
You may use GTK+. For graphs, cairo will be enough (it's the library used by GTK for drawing). But if you need nodes, lines and events (like moving stuff you have drawn), you'll need to use a canvas, like GooCanvas. You may also use GTK and Clutter.

What lib is usually to be used to develop a simple game like Tetris?

I am going to develop a Tetris in practice. But I have no idea how to start it, especially the graphic part - how to draw the frame and blocks? how to move them on screen?
Could you please you refer me to some useful libs or tools?
Programming language is c. (if this is done, I am planing to do it again with c++ and python. :) Both Windows or Unix-like is ok. It's better if it is portable.
I know openGL, and DirectX is heavy-weight lib. dose it efficiently fit to a small game like Tetris? Any light-weight? which is better?
I would appreciate if you could refer me to some materials or links for this.
Thanks.
If you'd like to keep your game in a window and not full-screen, then any library that implements some type of paintable canvas widget will work. Cross-platform candidates include Qt, WxWidgets, FLTK, GTK+, etc. If you want to remain on a single platform like Windows, then you can use a lower-level Win32 API like GDI+. As I mentioned in my first sentence, with most of these libraries/API's, you'd be looking to use their paintable canvas widgets, allowing you to draw the characters shapes on the window. You'd also use some type of timer event to periodically update the drawn window at fixed time intervals.
You can use SDL - is simple and many platforms are supported
I would suggest SDL or Allegro. Both provide simple ways of getting input and doing graphics and audio output. And both are multiplatform.

I want to make a GUI for a game coded in C for Linux Platform.Are there any API`s to do this or what woulb be the easiest way to make a gui

I want to make a GUI for a game coded in C for Linux Platform.Are there any API`s to do this or what woulb be the easiest way to make a gui.
SDL is best if you want to have a lot of action, with smooth animation, like this or this game . It is also very useful if your game is going to have 3D graphics.
Here is a list of SDL games.
SDL gets its excellent 3D capabilities through OpenGL. SDL also has decent sound capabilities.
GTK and QT work best for games where smooth animated movement all the time is not a requirement. Games like this. GTK & QT also works very well for games with simple animations like this. A huge list of GTK games.
However, to complicate things a bit, both GTK and QT have their own OpenGL extensions, which means you can develop fast-paced action games with those toolkits too.
There is also DirectFB which does not even need X11, just a framebuffer, but still has hardware acceleration.
Update:
based on ninjaljs suggestion that the OP might want a toolkit for widgets inside a game, here is a widget library for use within SDL.
What kind of game? There's several toolkits for normal GUI programming on X-windows. Check out gtk, Qt, wxWidget. If it's an action game meant to run outside of X or something, check out SDL.
A quick apt-cache search gives me libguichan and libparagui.

Resources