LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C Programming Simple Graphics Library (https://www.linuxquestions.org/questions/programming-9/c-programming-simple-graphics-library-4175499918/)

CincinnatiKid 03-29-2014 07:59 PM

C Programming Simple Graphics Library
 
I am looking for a simple 2d graphics library for C. What do you recommend. Mainly I want to set pixels, draw lines, squres, circles etc...

Thanks.

metaschima 03-29-2014 09:24 PM

I'd say use SDL + SDL_gfx. Modern, portable, easy to use.

Now I know some people are gonna recommend allegro ... no, just no.

smeezekitty 03-29-2014 10:04 PM

Definitely SDL. You have to write your own pixel routine but its pretty easy.
Its fast and cross platform too

metaschima 03-30-2014 12:44 PM

SDL_gfx lets you draw a 1x1 rectangle if you must have pixels.

John VV 03-30-2014 12:52 PM

or
have a look at CImg.h
yes it is a header ,but all the code needed is in it
http://cimg.sourceforge.net/
http://cimg.sourceforge.net/screenshots.shtml

metaschima 03-30-2014 01:32 PM

CImg is interesting, but maybe they should call it C++Img because it's not C, it's C++. Any way to write C code using it ?

smeezekitty 03-30-2014 01:50 PM

Quote:

Originally Posted by metaschima (Post 5143697)
SDL_gfx lets you draw a 1x1 rectangle if you must have pixels.

I think writing a pixel to the surface memory would have less overhead. Its so simple I don't know why more libraries don't support it

CincinnatiKid 03-30-2014 07:18 PM

I think I will give SDL_gfx a try since so many recommendations, and maybe CImg.h since it seems so simple.

Quote:

Originally Posted by smeezekitty (Post 5143731)
I think writing a pixel to the surface memory would have less overhead. Its so simple I don't know why more libraries don't support it

I know what you mean. I remember in Qbasic (sorry to bring up M$), it was just

Code:

PSET ([X coordinate], [Y coordinate]), [Colour of Pixel]

smeezekitty 03-30-2014 11:23 PM

Here is a simple pixel routine for SDL:
http://sdl.beuc.net/sdl.wiki/Pixel_Access

rtmistler 03-31-2014 01:10 PM

I've been using Fltk as a minimal replacement for Qt. No experience with SDL. I can say that I've run into questions for Fltk and asked them on stack overflow and gotten pretty prompt responses. Looks like it's under slow development.

What I like about it is similar to Qt, you take the source and build it on your target system. For me that's helpful since I swap between a variety of processor platforms.

Soderlund 03-31-2014 01:34 PM

I recommend XLib. You can set pixels and draw simple geometry, load images, et cetera.

metaschima 03-31-2014 02:05 PM

fltk and qt are GUI toolkits NOT graphics libraries.

theNbomr 04-03-2014 10:30 AM

You can easily generate images in many different file formats, and I think most would call that 'graphics'. What kind(s) of applications are you trying to create? There are already many different types of graphics applications; which ones(s) most closely resemble what you are trying to achieve? 'Graphics' can mean many things to many people, and is far too vague to allow people to make really useful suggestions. Is it your intent to create images programatically? What kinds of images? How will they be displayed? Will the rendering and the creation aspects be part of your application? On what kinds of device(s) will you imagery be rendered. Images created for a low resolution screen may not render well on a high resolution printer, but there are ways to generate resolution-independent images. Or do you intend to create some kind of interactive GUI with your graphics? That is a whole other level of graphical programming. There exist many libraries and APIs to support the whole spectrum of graphical programming. Without narrowing down your scope quite a bit, the spectrum of possible answers is too large to fit into a reply here.

piobair 04-04-2014 11:12 AM

I am not familiar with SDL. My one minute peek into SDL leads me to believe that it is a wrapper for OpenGL. Metaschima said that fltk and qt are GUI toolkits NOT graphics libraries. If you seriously interested in graphics programming, everything falls back onto OpenGL. It is directly supported by both NVIDIA and ATI, much to the discomfort of Microsoft (Not Invented Here). OpenGL Programming Guide (the Red Book) is all the tutorial that you will need to get started.

metaschima 04-04-2014 06:28 PM

If you want to start programming 3D or highly graphics intensive 2D games, then OpenGL would be very useful. You can use OpenGL within SDL. I know some games have a checkbox for turning OpenGL support on and off in case your graphics card doesn't support it ... rare nowadays.


All times are GMT -5. The time now is 09:29 PM.