LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-13-2011, 04:21 AM   #1
shivi91
LQ Newbie
 
Registered: Mar 2011
Location: india
Posts: 24

Rep: Reputation: 0
Graphics in c++ in fedora


i have newly installed fedora..and i wanted to know..whether the graphics in c++ can be used in a normal way...if not... i need the code for changing the background color and color of the font.
And i want to know..as we cannot use conio.h..how can we clear the screen..in turbo we used to use clrscr()..but what do we use in c++
Its for a project.
 
Old 03-13-2011, 08:03 AM   #2
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 4,788

Rep: Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486
Quote:
Originally Posted by shivi91 View Post
i have newly installed fedora..and i wanted to know..whether the graphics in c++ can be used in a normal way...if not... i need the code for changing the background color and color of the font.
I'm curious as to what you mean by "the normal way", but the way to change the background color and font depends on which widget toolkit you're using (Qt, GTK, etc). You'll have to look it up in the toolkit's API documentation.

Quote:
And i want to know..as we cannot use conio.h..how can we clear the screen..in turbo we used to use clrscr()..but what do we use in c++
Its for a project.
Use the s-lang library. Here is code to clear the screen with it:

http://www.jedsoft.org/slang/doc/htm...g-8.html#ss8.2

You can also use ncurses, as an alternative to s-lang.

Last edited by dugan; 03-13-2011 at 05:27 PM.
 
Old 03-14-2011, 08:06 AM   #3
shivi91
LQ Newbie
 
Registered: Mar 2011
Location: india
Posts: 24

Original Poster
Rep: Reputation: 0
hi..the normal way..as in there is code which comes with turbo c++..well i used that in one of ma projects in12th... it was pretty good..but that code actually doesn't work on linux....
 
Old 03-14-2011, 09:35 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by shivi91 View Post
hi..the normal way..as in there is code which comes with turbo c++..well i used that in one of ma projects in12th... it was pretty good..but that code actually doesn't work on linux....
Which probably means it is not the "normal way"

Given that you are talking about turbo C++ I'll assume that you are referring to the console. For that you will want to look at curses or one of its many derivatives.
 
Old 03-14-2011, 11:20 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Quote:
Originally Posted by shivi91 View Post
i have newly installed fedora..and i wanted to know..whether the graphics in c++ can be used in a normal way...if not... i need the code for changing the background color and color of the font.
What do you mean "graphics"? C++ has nothing to do with graphics, except if you use a game programming lib such as SDL or Allegro, or a GUI toolkit like GTK+ or Qt.

Quote:
Originally Posted by shivi91 View Post
And i want to know..as we cannot use conio.h..how can we clear the screen..in turbo we used to use clrscr()..but what do we use in c++
Its for a project.
If you're talking about text in a terminal, that's NOT graphics. Use a library such as ncurses.
 
Old 03-15-2011, 01:45 AM   #6
resetreset
Senior Member
 
Registered: Mar 2008
Location: India
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,320

Rep: Reputation: 62
My God, someone in India wanting to know about graphics programming in Linux - how could I NOT drop this on them:

hey Shiv, check this out, and start worshipping it:

en.wikipedia.org/wiki/Demoscene
 
Old 03-15-2011, 01:13 PM   #7
shivi91
LQ Newbie
 
Registered: Mar 2011
Location: india
Posts: 24

Original Poster
Rep: Reputation: 0
textcolor(RED);

textbackground(WHITE);
these were the functions used normally..with graphics.h header file..in turbo c++

it would really help if u give me the code...for making a square or changing the background color ..using c++ lang

Last edited by shivi91; 03-15-2011 at 01:21 PM.
 
Old 03-15-2011, 01:22 PM   #8
shivi91
LQ Newbie
 
Registered: Mar 2011
Location: india
Posts: 24

Original Poster
Rep: Reputation: 0
Smile

Quote:
Originally Posted by resetreset View Post
My God, someone in India wanting to know about graphics programming in Linux - how could I NOT drop this on them:

hey Shiv, check this out, and start worshipping it:

en.wikipedia.org/wiki/Demoscene
well i didn't have a clue abt this demoscene..thanks i got to know sumthin new
 
Old 03-15-2011, 01:44 PM   #9
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 4,788

Rep: Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486
Quote:
Originally Posted by shivi91 View Post
textbackground(WHITE);
these were the functions used normally..with graphics.h header file..in turbo c++

it would really help if u give me the code...for making a square or changing the background color ..using c++ lang
You really should be using OpenGL for your graphics.

Here's a very good series of tutorials:

http://nehe.gamedev.net/
 
Old 03-15-2011, 05:49 PM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
I doubt whether anyone on this forum considers Turbo C to be any kind of norm.

The C language does not include anything that is graphics-specific. Moreover, the Linux idiom of separation of purposes is very much in play with respect to the likes of graphics. The C language is supported mostly as the language spec defines it, and is not littered with unrelated elements. Even the term 'graphics' is a much too general term to be very meaningful. The term is used to describe everything from printed presentation graphics to many forms of graphical user interface.

It sounds like you want to write programs that draw graphical representations on a computer monitor. In Linux, this is usually accomplished by using a couple or more layers of existing APIs and libraries. Most often, at the lower level is the X windowing system, which provides a set of primitives that allow you to write basic pixel graphics to a computer monitor. This relieves you from dealing with the details of graphics hardware such as video cards and monitors, as well as a layer of networking, since X also gives you the ability to draw on remote X servers through an IP network. It also provides a way to get user input through keyboards and pointers.

There are a number of higher level APIs that provide simplified and consistent ways to do graphical things, such as create GUIs, render complex scenery, and game creation, to name a few. GUI oriented tools fall into the category of the Qt and GTK libraries. There are a plethora of library APIs with varying purposes, and many can be used in combination, such as for manipulating pixel graphics within a GUI widget.

It seems very likely that there is one or more existing libraries that can be employed to accomplish what you want. It is up to you to define your requirements, and find a suitable library or libraries that provide that kinds of services that you need. If you are able to provide a more refined definition of your requirements, someone on this and other forums can probably point you toward the appropriate libraries.

--- rod.

Last edited by theNbomr; 03-15-2011 at 05:51 PM.
 
Old 03-15-2011, 08:22 PM   #11
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by dugan View Post
You really should be using OpenGL for your graphics.
No. It IS an option, but not necessarily the best one.

Quote:
Originally Posted by MTK358 View Post
What do you mean "graphics"? C++ has nothing to do with graphics, except if you use a game programming lib such as SDL or Allegro, or a GUI toolkit like GTK+ or Qt.
Turbo C and Borland Pascal had a graphics module. I vaguely remember working with this thing before I decided to use dos graphic interrupts isntead. initgraph and such. It worked in CGA|EGA|Hercules video modes, if I remember correctly, so ncurses isn't it.

Quote:
Originally Posted by shivi91 View Post
turbo we used to use clrscr()..but what do we use in c++
AFAIK, you have two options.
  • If you want to draw graphics in fullscreen (at high speed), you'll have to use libSDL, maybe in combination with OpenGL. The problem is that raw SDL works only with surfaces, and doesn't even have "draw line" routines (there might be an addon SDL_"something" library for that, though). And basic OpenGL works only with with points, lines, triangles and textures. It doesn't even support text rendering out of the box (because text rendering is OS-dependent, and OpenGL is cross-platform).
  • If you want richer rendering capabilities, then you'll have to draw things using a GUI toolkit (such as Qt 4, which I'd recommend) in a window. It will be easier than dealing with SDL+OpenGL (there will be line/spline/circle/ellipse/line segment rendering functions), but you'll have to get familiar with concepts that didn't exist in graphics module (such as widgets, windows, etc).

There may be other libraries (I've never even heard of) suitable for your task. SVGAlib might offer something similar, but I see no reason to use it on a modern machine. Or you could search sourceforge for desired library.
 
Old 03-16-2011, 08:54 AM   #12
resetreset
Senior Member
 
Registered: Mar 2008
Location: India
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,320

Rep: Reputation: 62
Quote:
Originally Posted by shivi91 View Post
well i didn't have a clue abt this demoscene..thanks i got to know sumthin new
The day the itch gets to be too bad for you, and you can't HELP yourself from trying to write your own demo, well - THAT's the day we're all waiting for.


Hey PM me your email address, let's keep in touch. Where in India are you?
 
Old 03-17-2011, 11:25 AM   #13
shivi91
LQ Newbie
 
Registered: Mar 2011
Location: india
Posts: 24

Original Poster
Rep: Reputation: 0
well
as i am a newbie please i need the proper code and i have no clue abt the high tech terms that every1 is using...anyone please with simple code to change the colour of the text and backgound..i want to do that when i am running the program.i want ma project to be a lil colourful.
 
Old 03-17-2011, 12:18 PM   #14
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Sorry, it just isn't that simple. You are asking for instructions on how to do something that can be done many different ways, many of which have been listed for you. If you are going to program in Linux, you cannot expect to use semantics that are specific to a completely different architecture. It just doesn't work that way.
Perhaps if you show us some code (use [CODE ] tags), or at a minimum, describe what you program does and what general characteristics it has, someone can make more specific suggestions. Are you using a GUI application (not likely, if you are a newbie), or using strictly text console for input and output (considered to be NOT graphics, even in Turbo C). If the latter, then you almost certainly want to use ncurses.

--- rod.
 
Old 03-17-2011, 12:24 PM   #15
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Quote:
Originally Posted by shivi91 View Post
well
as i am a newbie please i need the proper code and i have no clue abt the high tech terms that every1 is using...anyone please with simple code to change the colour of the text and backgound..i want to do that when i am running the program.i want ma project to be a lil colourful.
First, please spell out your words correctly if it's not too hard for you. It's a bit difficult to read.

If you mean changing the color of the text in terminal output, that has zero to to with graphics and you should quit calling it that. Here are some good resources:

http://www.google.com/search?q=ansi+...ient=firefox-a
http://www.google.com/search?q=ncurs...ient=firefox-a

Or if you really want do draw text to a graphical window (not print to a text terminal), then you will just have to learn the "high tech terms" because it's not that simple and there isn't one, fixed, "right" way of doing it. You can ask us about what confuses you the most.

Last edited by MTK358; 03-17-2011 at 12:27 PM.
 
  


Reply

Tags
c++, graphics


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
[SOLVED] ATI graphics on Fedora 14 Dagorath Linux - Hardware 3 03-03-2011 06:55 AM
Graphics problem in fedora 10.. RAJEEV N BHARSHETTY Linux - Newbie 1 09-09-2009 09:01 AM
What are you using for a graphics card in Fedora? moxieman99 Fedora 3 03-19-2009 11:56 AM
graphics.h in fedora kantu Linux - Newbie 1 10-14-2008 12:26 PM
fedora 3 problem with graphics anjani.78 Linux - Newbie 8 07-05-2005 09:53 AM


All times are GMT -5. The time now is 08:51 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration