LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2014, 07:59 PM   #1
CincinnatiKid
Member
 
Registered: Jul 2010
Posts: 454

Rep: Reputation: 47
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.
 
Old 03-29-2014, 09:24 PM   #2
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
I'd say use SDL + SDL_gfx. Modern, portable, easy to use.

Now I know some people are gonna recommend allegro ... no, just no.
 
Old 03-29-2014, 10:04 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Definitely SDL. You have to write your own pixel routine but its pretty easy.
Its fast and cross platform too
 
Old 03-30-2014, 12:44 PM   #4
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
SDL_gfx lets you draw a 1x1 rectangle if you must have pixels.
 
Old 03-30-2014, 12:52 PM   #5
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,517

Rep: Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619
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
 
Old 03-30-2014, 01:32 PM   #6
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
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 ?
 
Old 03-30-2014, 01:50 PM   #7
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by metaschima View Post
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
 
Old 03-30-2014, 07:18 PM   #8
CincinnatiKid
Member
 
Registered: Jul 2010
Posts: 454

Original Poster
Rep: Reputation: 47
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 View Post
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]
 
Old 03-30-2014, 11:23 PM   #9
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Here is a simple pixel routine for SDL:
http://sdl.beuc.net/sdl.wiki/Pixel_Access
 
Old 03-31-2014, 01:10 PM   #10
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,262
Blog Entries: 13

Rep: Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350
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.

Last edited by rtmistler; 03-31-2014 at 01:12 PM.
 
Old 03-31-2014, 01:34 PM   #11
Soderlund
Member
 
Registered: Aug 2012
Posts: 185

Rep: Reputation: 81
I recommend XLib. You can set pixels and draw simple geometry, load images, et cetera.
 
Old 03-31-2014, 02:05 PM   #12
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
fltk and qt are GUI toolkits NOT graphics libraries.
 
Old 04-03-2014, 10:30 AM   #13
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
1 members found this post helpful.
Old 04-04-2014, 11:12 AM   #14
piobair
Member
 
Registered: Aug 2013
Distribution: Debian, Ubuntu
Posts: 230

Rep: Reputation: Disabled
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.
 
Old 04-04-2014, 06:28 PM   #15
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Graphics Library and building a simple GUI richman1234 Linux - Newbie 1 08-10-2010 09:14 AM
what is the function library of the basic graphics library in rethat9.0? zerwolve Red Hat 0 04-29-2004 09:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration