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/)

MTK358 03-20-2011 08:19 AM

@shivi91

It looks like you want graphics, not colored text. (Why didn't you clearly say that anywhere?!?)
There are two main kinds of graphics/GUI libraries:

First are GUI toolkits (typically used for desktop applications). They provide you with buttons, labels, text entries, and just about any other control you can think of. You can also create your own widget (control) and draw in it. The main choices are GTK+ (or its C++ binding, gtkmm) and Qt.

And second there are game libraries (typically used for video games). They mostly handle only image files and are made for drawing complex scenes made out of lots of them really fast. They also often provide functions for audio and input devices, and some support 3D graphics. Popular ones for Linux include SDL and Allegro.

theNbomr 03-20-2011 11:32 AM

shivi91: Your code demonstrates that you are trying to produce a GUI. You have code which renders pixel graphics to a computer monitor, and you have code that acquires input from an interactive user.
Code:

/* draw a rectangle */

rectangle(left,top,right,bottom);

/* clean up */

getch();

To create GUIs in Linux, you can proceed in one of at least two ways. You can use one of the common GUI toolkits, such as GTK or Qt. Or you can develop your own GUI, building your own widgets and so on from a lower level library or libraries. While this seems to be the method demonstrated by your code, I would consider it by far the least desirable approach.

Your code will never compile and run under Linux directly. There are no libraries that directly implement the semantics given in your code. The Turbo C graphics library is a very poor and incomplete toolkit for developing any kind of GUI (and is the reason that things like Windows and X-Windows were designed). The Turbo C graphics library is targeted to a very specific architecture; one which is very dissimilar to most architectures found on common Linux desktop environments. Your best hope to run the code you posted (ever think of posting in [CODE ] tags?) might be to run it in some kind of emulator. For that, you would need to build it with the native Turbo C compiler.

--- rod.

MTK358 03-20-2011 12:23 PM

Quote:

Originally Posted by theNbomr (Post 4297097)
To create GUIs in Linux, you can proceed in one of at least two ways. You can use one of the common GUI toolkits, such as GTK or Qt. Or you can develop your own GUI, building your own widgets and so on from a lower level library or libraries. While this seems to be the method demonstrated by your code, I would consider it by far the least desirable approach.

I agree. Writing GUI elements yourself is a waste of time, and will never come close to the functionality, look, and feel of a real toolkit.

Just check out GTK+ and Qt, pick one (personally I think Qt is easier to work with and has more features), and use it. They even have nice GUI programs to build the interface of your program before you even start writing code (Qt Designer for Qt, and Glade for GTK+).

shivi91 03-21-2011 11:51 AM

dos.h doesn't work either..what should be done for that?

MTK358 03-21-2011 12:01 PM

There is no direct equivalent of dos.h in standard C.

Instead, use this: http://en.wikipedia.org/wiki/Libc

shivi91 03-21-2011 12:13 PM

Quote:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
main()
{

int ch;

char pword[8];

int i = 0;



cout << endl << " Enter system password : ";

fflush(stdout);



while ((ch = getch()) != EOF && ch != '\n' && ch != '\r' && i < sizeof(pword))

{

if (ch == '\b' && i > 0)

{

printf("\b \b");

fflush(stdout);

i--;

pword[i] = '\0';

}

else if (isalnum(ch))

{

putchar('*');

pword[i++] = (char)ch;

}

}

pword[i] = '\0';

if(strcmp(pword, "Teacher8")==1)
cout<<"workd";

}





while ((ch = getch()) != EOF && ch != '\n' && ch != '\r' && i < sizeof(pword))//how would this be converted to linux code..

shivi91 03-21-2011 12:16 PM

i want the input to be stars like inputing password... that was the code which worked in turbo..

MTK358 03-21-2011 12:33 PM

Quote:

Originally Posted by shivi91 (Post 4298232)
while ((ch = getch()) != EOF && ch != '\n' && ch != '\r' && i < sizeof(pword))//how would this be converted to linux code..

Is "pword" a variable name or some kind of data type found in Turbo C/dos.h?

Please post the code in BBCode [code]code goes here[/code] tags. It will use a monospaced font and preserve indentation.

Quote:

Originally Posted by shivi91 (Post 4298233)
i want the input to be stars like inputing password... that was the code which worked in turbo..

EDIT: There is no nice, cross-platform way of preventing typed characters from being echoed. If you will only use the GNU implementation of libc (glibc, used in almost all Linux systems), then you can use this: http://www.gnu.org/s/libc/manual/html_node/getpass.html

shivi91 03-22-2011 07:32 AM

Quote:

Originally Posted by MTK358 (Post 4298253)
Is "pword" a variable name or some kind of data type found in Turbo C/dos.h?
l[/url]

pwrod is a varible..that is like the password we trying to enter

MTK358 03-22-2011 07:56 AM

Did you read the part of my post about not echoing, and did you understand it? (By the way, why do you keep ignoring so many of our questions? I still don't understand what you meant by "graphics" or what you want to do!)

From what I understand, this should do what you want (warning: not tested). Requires you to include termios.h.

Code:

struct termios termios_old, termios_new;

if (tcgetattr(fileno(stdin), &termios_old) != 0) {
        // stuff to do if failed to get terminal settings
}
termios_new = termois_old;
termios_new.c_lflag &= ~ECHO;
if (tcgetattr(fileno(stdin), TCSAFLUSH, &termios_new) != 0) {
        // stuff to do if failed to set terminal settings
}

// typed characters will not echo now

tcgetattr(fileno(stdin), TCSAFLUSH, &termios_old);

// typed characters will echo again now



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