I have come across a project where it is required to draw some 2D graphics on a form under Windows and to be able to perform the following tasks:
read image formats jpg, GIF, png, with transparency
monitor mouse and keyboard input to this form
draw simple 2D shapes, eg. line, ellipse, rectangle, pixel set/clear, polygons, ...
draw text with true font types and sizes and measure text sizes for different strings
written in C and can be integrated into Visual Studio 2008 C project
I've tried OpenCV but it lacks the transperency, font types, and GIF decoding and other things
I need your help please, It would be good if the library is easy to learn and use
thanks all
Sounds like a perfect job for SDL
And why not use the GDI built into Windows?
Traditional GDI documentation - http://msdn.microsoft.com/en-us/library/dd145203%28v=VS.85%29.aspx
Newer GDI+ documentation - http://msdn.microsoft.com/en-us/library/ms533798%28VS.85%29.aspx
Some more info added:
I guess I don't understand your requirements. Is cross platform support required? If yes, then use C and some of the cross platform libraries people have mentioned. If this is Windows only, then why not use the APIs that come with Windows?
Since your already using Visual Studio and you want ease of learning and development, why don't you use C# and the.NET libraries? In 2010, that is really the easiest way to build Windows only programs. Windows Forms will likely do everything you need. If you really must write in C and you are Windows only, then use GDI+ (or GDI if you need to support older versions of Windows). If you want to learn classic Windows C programming, go to the source - http://www.charlespetzold.com/pw5/.
As daddz said, you can use SDL for inputs, and image reading. In order to render your 2D primitives, OpenGL will do the work (be sure to create an OpenGL compatible window while calling SDL_CreateWindow). Concerning font rendering, it is not directly implemented in SDL but a couple of libraries can be used (see Survey Of OpenGL Font Technology).
Related
How can I draw just a pixel in C programming?
I feel if I know this, I can build a whole lot of codes for drawing many objects line, circle etc.
I am using fedora 17 (linux) on intel chip.
Am I being too hopeful?
You can start with OpenGL.
Read this wiki page
install your suitable graphics driver from Here
Start programming
Do you want to draw pixel on a screen, or text file, or a picture format file (jpg, bmp)? If it's screen you would be better off using a library which allows you draw graphics such as SDL. If it's a text file, well there is not much to explain except to open a file and write to it. If it's picture format output there are other libraries out there that would create picture files for you. doing a quick search I found this: http://freeimage.sourceforge.net/
There's not a standard for graphics programming in C, it completely depends on what environment you are running in. If you're targeting Linux, then that usually means X11. Read up on Xlib, or a widgit library like Qt or Gtk.
I'm making program using Allegro5, but I'm not familiar with the library yet. I just want to know what is possible with this library.
I have to do 'color correction of image' (contrast, brightness, etc.) and I thought about:
-making buttons (like in normal windows program),
-scrollbars,
-file loader - I click on the button and I'm allowed to jump through directories on my hard drive and pick image file i want to edit in my program
-opening windows in allegro window (for the preview or something)
etc.
I want to use for that as much OOP as I can (i know, it's C). Is it possible to do all of that in C and Allegro5, or i need windows libraries and other stuff as well?
Thanks in advance for your replies. :)
Yes, you can do all of those things, but Allegro 5 is primarily designed for games and not GUI applications. It has support for native menus (5.1 series) and dialogs, but you're on your own regarding buttons, sliders, etc. (There are some third party GUI libraries available, but none of them would look like a native application.)
So if your program is basically a GUI application, then you're probably best off using something like Qt or GTK as your foundation, and only using a graphics library as needed.
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'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.
I have this confusion to develop this application in Win32 or WPF (.NET). This application primarily consists of a text editor (think of similar to the one in MS OneNote) with lot of customized requirements compared to a general text editor.
I was thinking to use VC to work on this as lots of custom drawing is required. What do you guys suggest? Is WPF is a best deal for this sort of applications? Or Win32 is better to go?
If you want to write any sort of GUI app on Windows, I would recommend not using C++. .NET is much, much better for creating a GUI than all of the various C++ GUI libraries that are on Windows. I could see using WPF for writing an app like OneNote working out fairly well, since WPF is very easily extensible.
If you want to use a commercial WPF Text Editor you can check out one from ActiPro: http://www.actiprosoftware.com/Products/DotNet/WPF/SyntaxEditor/Default.aspx