I'm trying to learn some graphics programming using C. What would be the best way for a beginner to start? I'd like to how to make programs that use graphics and images that can be run directly from a command line prompt, and don't rely on a windowing system like X to execute.
Thanks,
Mike
Look into libsdl - Simple DirectMedia Layer. Although on Linux it can use X11 for displaying output, it can also directly use a framebuffer device. It's designed to be simple for pixel-bashing game-type programming, and supports a wide variety of platforms.
There's also Allegro if you're not a fan of SDL. It's somewhat more fully-featured for simple vector graphics; SDL is mainly a cross-platform framebuffer until you add extension libraries.
Learn some GUI toolkit like Qt or GTK, this way you will make modern GUI applications.
Check out the FLTK GUI toolkit. It is small and easy to learn.
Related
I wrote a process explorer using C with GUI interface. I want to add a graph to show the CPU status. Which library or functions can help me to do that?
You can use Cairo, it's a simple 2D graphics library written in C.
you may use curses windows impelementation which called pdcurses
You can use OpenGL for High Performance Graphics
Okay, I'd like to write a simple C app for Linux (say Ubuntu with Gnome) that would do the following:
Open a Window
Draw something in that window using a main loop, e.g. the current loop number. I don't want to use controls, but to draw directly on the window surface
Close the window & the app
I can do that in Windows, but I've no idea how I could do that in Linux.
Thanks!
Unless you want a full-blown GUI (in which case I'd recommend Qt or GTK), then SDL is a very popular and extremely simple free cross-platform library that gives you a drawing surface and some simple IO facilities. It's natively C, but has bindings to a large number of other languages.
There are various "Hello World" examples for X11 programming.
Using GTK+:
http://library.gnome.org/devel/gtk-tutorial/2.13/c39.html
Using Qt:
http://doc.qt.nokia.com/latest/tutorials-widgets-toplevel.html
Using wxWidgets:
http://www.wxwidgets.org/docs/tutorials/hello.htm
There are a lot more toolkits: Fox, FLTK, Tk, EFL ...
So far these have all been cross-platform, so let's have a look at X11-specific exampls:
This is using Xlib:
http://en.literateprograms.org/Special:Downloadcode/Hello_World_(C,_Xlib)
And this is using Xcb:
http://xcb.freedesktop.org/tutorial/basicwindowsanddrawing/
If you only want to draw something, why not just use OpenGL and GLUT. The latter provides simple methods to create a window with an OpenGL context.
Setting up a GLUT application is very straighforward and there are lots of tutorials out there , e.g. Lighthouse3d.com. This tutorial works with visual studio, but it's not hard to translate this to compiling an application on Linux.
Alternatively, you could also work with Qt, which is a more advanced and easy to use GUI toolkit, and which would not necessarily require you to write OpenGL code.
Since you mentioned C, there is Glade if you want to make use of GTK+ for a nice little editor that allows you to draw controls onto a window.
Alternatively if you have access to a C++ compiler you can have a look at Qt which provides similar functionality.
Well, if you're familiar with making gui apps in windows I'm going to take a guess that you've done it with .net or something similar. An easy transition would be to use mono. A cross platform .NET development platform - http://mono-project.com/Main_Page
There's also has a variety gui toolkits to use: http://www.mono-project.com/Gui_Toolkits
If you want to draw directly onto the window, have you considered X11?
It's not going to be as nice as working with a toolkit like GTK or Qt, but it's about as low level as you can get in the windowing system.
I don't have any experience with programming straight X11, so I can't recommend any starting material.
I have a bunch of simple programs that I would like to display in a GUI window rather than a DOS terminal. How can I accomplish this? Do I need to call upon a library or what? Thanks.
You will need to use a library to do this; the C language does not define any windowing or GUI constructs. Since you're talking about DOS terminals, I'm assuming that you're in Windows, and so you might want to look at the Windows API, which is a C library with all sorts of powerful windowing tools. You might also want to look at one of the many wrapper libraries that are layered on top of this API, like MFC or WPF.
you need to create a windows application project in your compiler, any compiler i know has that option, and include the windows.h library (#include ).
Have a look at the gtk library http://www.gtk.org and if you feel comfortable with c++ i recommend you wxwidgets GUI framework http://www.wxwidgets.org.
is it possible to develop a GUI in linux c??
how can be do that??
If you want to develop GUI applications for Linux with pure C you can use GTK+. IF C++ is an option you also have Qt.
There are many graphical toolkits for linux such as GTK, Qt, wxWidgets, and FLTK. They have bindings for many languages such as C and Python. I suggest you google around to see what you like. If you want a RAD you may want to check out things like glade and qt creator.
Yes. Use a GUI toolkit such as GTK+ that uses C, or find a wrapper for one of the various C++ toolkits.
XForms is a graphical user interface toolkit for X based on the X11 Xlib library. I.e., it allows you to create windows, containing all kinds of widgets (buttons, sliders, browsers, menus etc.) with a few lines of code and then attach actions to the widgets, i.e., have some function called when a button is pressed. To make this even easier XForms comes with a program called fdesign that allows you to design a GUI for a program directly on the screen and which then writes out the necessary C code for it.
XForms is written in C and has a C API, i.e., you can use it directly from a C program. It should work with X11 R4, R5, R6 & R7 and under all kinds of operating systems of the UNIX family (including MacOS X) as well as at least OpenVMS, OS/2 und Windows NT 4.0. In addition, the library is extensible and new objects can easily be created and added to the library.
http://xforms-toolkit.org
I would recommend FLTK. It may be difficult to write complex interface with it. But FLTK, as its name implies, is very small and fairly fast. What is more important, it is cross-platform, working nicely on the three major OS: linux, windows and mac. In my view, GTK/Qt/wxWidgets are far too heavy. If you statically link to these library, you will end up with a huge executable which eat up the memory; if you dynamically link to them, users have to install the library before hand, which is always troublesome.
EDIT: I just realize that this is a "C" question. Then the best choice should be GTK. If you need graphics but not interface/widgets (e.g. menu, scrollbar and so on), opengl is also nice.
Until now I've been only writing console applications but I need to write a simple window application for a school assignment.
Could somebody point me to a good tutorial how to create windows and other ordinary windows elements such as buttons, 2d graphs etc in ANSI C? is there some good library I should use?
I tried googling but there are no tutorial websites devoted to C.
If you can, I would also appreciate some example code.
Thank you.
By the way, I use Dec C++.
GTK is a good library to use, but may provide non-native looks under Windows. It looks great under GNU/Linux, especially using GNOME.
It is implemented in just C (Using the GObject Type System, part of the GLib library), so it will work great for your needs. There is also a RAD tool called Glade.
There's nothing in the ANSI C standard about windows. If you want to make a windowed application, you'll have to use platform-specific libraries (e.g. Win32, Cocoa, or X11), or some sort of cross-platform library that encapsulates that (e.g. SDL, wxWidgets, or many more).
Common places to start are Charles Petzold's Programming Windows and theForger's Win32 API Programming Tutorial.
However in most cases C is no longer the preferred language for Windows development. Object oriented technology is far better suited to GUI development, and with the introduction of MFC, C++ became the preferred language, and later with .Net, C# and C++/CLI.
The Win32 API can be hard work, much of MFC is little better than a Win32 API wrapper, the .Net framework however was designed from the ground up, and is less encumbered by the legacy of the Win32 API monster, and working with it tends to result in far greater productivity.
Either way, Dev-C++ is not a great tool for GUI development.
http://support.microsoft.com/kb/829488 which also talks how to create
Windows application: Creates a simple
Microsoft Windows-based application.
The application files include a
ProjectName.cpp file that contains a
_tWinMain function. You can use this type of application to perform
graphical user interface (GUI) based
programming.
As for tutorials... use MSDN. Win32 API is C. You don't need "Win32 ANSI C tutorial" - you need Win32 tutorial (for example http://www.winprog.org/tutorial/start.html, http://www.functionx.com/win32/Lesson01.htm) - unless, of course, you don't know ANSI C but then you just look for ANSI C tutorial. These subjects are independent.
There are lots of good libraries—too many for there to be an obvious choice without starting a religious war. I recommend that for your first library you learn something that will work on Windows, Linux, or OSX. Here are two good choices, not necessarily the best, but widely used and personal favorites:
Tcl/Tk. You write most of your application in the Tcl scripting language, but you can easily integrate your own ANSI C code into Tcl, which was designed from the beginning with such integration in mind. The Tk toolkit is very easy to learn, and you can write many simple GUIs in pure Tcl when you are getting started. Interactive, easy, and very well supported.
If you want to write everything in ANSI C, I don't know of any really simple choices, but I've been fairly happy with wxwidgets. All these tools have a pretty steep learning curve, however.
There are not many plain C GUI libraries as the strengths of the language lie elsewhere. Perhaps you should think about using a language with C bindings so you can still do the number crunching in C, but use something less painful for GUI development?
If you really want to stick to C, you can either use the OS' native API or the only current cross-platform C GUI lib I'm aware of: GTK+. If you don't really need a GUI but just graphical output, I'd go with SDL.
I suggest you download Microsoft Visual Studio 2008 Express Edition and use C#.Net.
As has been said, I suggest you use Winforms and switch to a .Net environment. It's 2009, and I think there are more suitable solutions to GUI's :P
Edit: Nvm, didn't see it was a school assignment.
However, here is a C++ guide on the Win32 API: http://www.relisoft.com/win32/index.htm