LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Graphics in c++ in fedora (https://www.linuxquestions.org/questions/programming-9/graphics-in-c-in-fedora-868257/)

shivi91 03-13-2011 04:21 AM

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.

dugan 03-13-2011 08:03 AM

Quote:

Originally Posted by shivi91 (Post 4288872)
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.

shivi91 03-14-2011 08:06 AM

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....

graemef 03-14-2011 09:35 AM

Quote:

Originally Posted by shivi91 (Post 4290181)
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.

MTK358 03-14-2011 11:20 AM

Quote:

Originally Posted by shivi91 (Post 4288872)
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 (Post 4288872)
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.

resetreset 03-15-2011 01:45 AM

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

shivi91 03-15-2011 01:13 PM

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

shivi91 03-15-2011 01:22 PM

Quote:

Originally Posted by resetreset (Post 4291120)
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:):)

dugan 03-15-2011 01:44 PM

Quote:

Originally Posted by shivi91 (Post 4291713)
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/

theNbomr 03-15-2011 05:49 PM

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.

SigTerm 03-15-2011 08:22 PM

Quote:

Originally Posted by dugan (Post 4291730)
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 (Post 4290357)
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 (Post 4288872)
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.

resetreset 03-16-2011 08:54 AM

Quote:

Originally Posted by shivi91 (Post 4291715)
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?

shivi91 03-17-2011 11:25 AM

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.

theNbomr 03-17-2011 12:18 PM

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.

MTK358 03-17-2011 12:24 PM

Quote:

Originally Posted by shivi91 (Post 4294044)
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.


All times are GMT -5. The time now is 03:26 AM.