Thread: Portable, simple text-based graphics C library or stuff?

  1. #1
    Registered User
    Join Date
    Sep 2013
    Location
    Lithuania
    Posts
    3

    Question Portable, simple text-based graphics C library or stuff?

    Hello guys, I just finished reading a C book. Now I want to make some serious programs! And I'm not into shiny nice graphical programming (I tried SDL and I didn't like it). I want to stick to the text-based graphics applications. Anyone knows a simple library, which would be:
    • Portable (Linux (ubuntu) and Windows).
    • Simple (no very sophisticated stuff).
    • Would let me to manage the terminal size (fullscreen, buffer size).
    • Would let me to manipulate cursor (gotoxy).
    • Would let me to change background and text color.


    Anyone? Mouse handling and scrolling and every other stuff would be cool but is not that important

    If this is a stupid question, please, don't blame me, I'm new to programming and I'm learning by myself.

    And what about ncurses library? I installed it, it's HOWTO offers great features, but I'm not sure about it's portability and fullscreen windows.

  2. #2
    Registered User
    Join Date
    Sep 2013
    Posts
    3
    try this
    if you want to learn mouse handling
    Code:
    #include<dos.h>
    #include<graphics.h>
     
     
          union REGS i,o;
          main()
               {
               int gd=DETECT,gm,maxx,maxy,x,y,button;
               initgraph(&gd,&gm,"c:\\turboc3\\bgi");
               maxx=getmaxx();
               maxy=getmaxy();
               rectangle(0,56,maxx,maxy);
               setviewport(1,57,maxx-1,maxy-1,1);
               gotoxy(26,1);
               printf("MouseDemostration program");
               if(initmouse()==0)
               {
               closegraph();
               restorecrtmode();
               printf("\n mouse driver not loaded");
               exit(1);
     
               }
               restrictmouseptr(1,57,maxx-1,maxy-1);
               showmouseptr();
               gotoxy(1,2);
               printf("Left button");
               gotoxy(15,2);
               printf("Right button");
               gotoxy(55,3);
               printf("press anaykey to exit");
               while(!kbhit())
               {
                getmousepos(&button,&x,&y);
                gotoxy(5,3);
                (button&1)==1?printf("down"):printf("up");
                gotoxy();
                (button&2)==2?printf("Down"):printf("Up");
                gotoxy(65,2);
                printf("X=%03d y=%03d",x,y );
               }
               return;
               }
               initmouse()
               {
               i.x.ax=0;
               int86(0x33,&i,&o);
               return(o.x.ax);
               }
               showmouseptr()
               {
                i.x.ax=1;
                int86(0x33,&i,&o);
                return;
               }
     
               restrictmouseptr(int x1,int y1,int x2,int y2)
               {
                i.x.ax=7;
                i.x.cx=x1;
                i.x.dx=x2;
                int86(0x33,&i,&o);
                i.x.ax=8;
                i.x.cx=y1;
                i.x.dx=y2;
                int86(0x33,&i,&o);
                return;
                }
                getmousepos(int *button,int *x,int *y)
                {
                 i.x.ax=3;
                 int86(0x33,&i,&o);
                 *button=o.x.bx;
                 *x=o.x.cx;
                 *y=o.x.dx;
                 return;
                }

  3. #3
    Registered User
    Join Date
    Sep 2013
    Location
    Lithuania
    Posts
    3
    Quote Originally Posted by satyam0507 View Post
    try this
    if you want to learn mouse handling
    Code:
    #include<dos.h>
    #include<graphics.h>
    /* code... */
    I doubt if this answers my question and will be portable to Linux (I'm using lubuntu). I need a text-based portable graphics library, not just handling of mouse. I know how to handle mouse with SDL library, but it's object-based graphics library...

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    This is not really a C question. It properly belongs in linux programming (or, maybe, windows programming).

    ncurses meets most of your requirements - such as they are - although "simple" is subjective. IIRC, there is a GNU windows port that makes use of the win32 Console API. And it originated under linux, was ported to other unitx variants.

    Since text-based graphics are not exactly the default under modern GUI based OS, you'll probably need to run your program in a terminal window.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Registered User
    Join Date
    Sep 2013
    Location
    Lithuania
    Posts
    3
    Quote Originally Posted by grumpy View Post
    This is not really a C question. It properly belongs in linux programming (or, maybe, windows programming).
    Well, I'm searching for portable language, so then it should be posted on both of those forums.
    Quote Originally Posted by grumpy View Post
    ncurses meets most of your requirements - such as they are - although "simple" is subjective. IIRC, there is a GNU windows port that makes use of the win32 Console API. And it originated under linux, was ported to other unitx variants.
    Is that port PDCurses? (c++ - Is ncurses available for windows? - Stack Overflow)
    Quote Originally Posted by grumpy View Post
    Since text-based graphics are not exactly the default under modern GUI based OS, you'll probably need to run your program in a terminal window.

    That is what I hate about modern OS! Each compiled language programmer starts with a console! All his first programs and enthusiasm goes into that console! And all he gets is bare boring functions! No graphics! He cannot change colors, because that would be not portable, he cannot read characters without user pressing enter key (that would require other libraries that support portability), he cannot add any sounds at all, his program has to fit on a single tiny 80x25 console screen and there is no option to make it fullscreen! It's HORROR! I think that at the beginning so many programmers are "killed" because of these reasons! And why nobody can create a portable, nice text-based graphics library that would brighten the lives of all programmers beginners? To allow them to make cool games like snake, PacMan or even some RPGs in fullscreen? WHY???

    We should make one header like that. That would greatly increase the popularity of C and C++. People could make some COOL text-based games easily (because object-based programming is not that easy), although with effort. I can't believe nobody did this already. Imagine, any beginner just types in
    #include <learning_kit.h>
    and he's ready to make cool things without being a professional programmer!
    Last edited by Mark Miller; 09-21-2013 at 06:29 AM.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Mark Miller View Post
    Well, I'm searching for portable language, so then it should be posted on both of those forums.
    What you're seeking is not a portable language. It is a portable library.

    Quote Originally Posted by Mark Miller View Post
    That's one option. There are others.

    Quote Originally Posted by Mark Miller View Post

    That is what I hate about modern OS! Each compiled language programmer starts with a console! All his first programs and enthusiasm goes into that console! And all he gets is bare boring functions! No graphics! He cannot change colors, because that would be not portable, he cannot read characters without user pressing enter key (that would require other libraries that support portability), he cannot add any sounds at all, his program has to fit on a single tiny 80x25 console screen and there is no option to make it fullscreen! It's HORROR! I think that at the beginning so many programmers are "killed" because of these reasons! And why nobody can create a portable, nice text-based graphics library that would brighten the lives of all programmers beginners? To allow them to make cool games like snake, PacMan or even some RPGs in fullscreen? WHY???


    Why? Because companies seek profits, and the end-users they make profits from are interested in the user experience. Although programmers are central to developing an OS, catering to their interests does not make an OS profitable.

    Much as linux, BSD and variants are popular in the techie community, they are not dominant because techies are vastly out-numbered by non-techies.

    Quote Originally Posted by Mark Miller View Post
    We should make one header like that. That would greatly increase the popularity of C and C++. People could make some COOL text-based games easily (because object-based programming is not that easy), although with effort. I can't believe nobody did this already. Imagine, any beginner just types in
    and he's ready to make cool things without being a professional programmer!
    C and C++ are actually doing quite well on their own among professional and non-professional developers.

    You're under-estimating the aspirations of most people who take up software development though. Those who are genuinely interested in it will learn, and find (or develop if they have to) libraries to do what they seek. They will persist, because that is their nature. If they want a console library, they will find an implementation of ncurses or roll something that is smaller and fit for their purpose.

    However, those who take up development for other reasons vastly outnumber those who are genuinely interested in learning. Most people who take up some form of development are not truly interested in it. Those people include the ones who find they have to do a programming subject as part of another course (law, mathematics, science, etc etc), moan about the lack of easy to use libraries, try to get someone else to do their work, and often consider developers as some lower form of life.

    There is certainly room for improvement of C, C++, and their libraries. But don't make the mistake of believing that creating a single library will suddenly increase the popularity of C and C++. Even if your library is a hit among amateur developers.
    Last edited by grumpy; 09-21-2013 at 05:32 PM.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Mark Miller View Post
    That is what I hate about modern OS! Each compiled language programmer starts with a console! All his first programs and enthusiasm goes into that console! And all he gets is bare boring functions! No graphics! He cannot change colors, because that would be not portable, he cannot read characters without user pressing enter key (that would require other libraries that support portability), he cannot add any sounds at all, his program has to fit on a single tiny 80x25 console screen and there is no option to make it fullscreen! It's HORROR!
    "Portability" is a complicated concept. The portability of code is related to how heavily it makes use of abstractions. For instance, if you use the SDL library for graphics and sound, you gain some degree of portability by relying on SDL as an abstraction layer. True, SDL is not portable to all platforms, but the SDL API could theoretically be targetted to any arbitrary graphics platform. The first step to portability is defining an interface.

    Be careful not to confuse portability with standards. Code doesn't have to be standard to be portable, it just has to rely on an abstraction instead of doing things concretely. The "one header like that" which you refer to could be SDL, for instance.

    And I wouldn't worry about the popularity of C and C++. These languages are heavily used in the infrastructure layers of almost all modern computing devices. They are not going ANYWHERE.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  8. #8
    Registered User
    Join Date
    Sep 2013
    Location
    Lithuania
    Posts
    3
    Quote Originally Posted by grumpy View Post
    What you're seeking is not a portable language. It is a portable library.
    Sorry. You know when you're thinking about one thing, but writing another? That was the case, sorry.
    Quote Originally Posted by grumpy View Post
    You're under-estimating the aspirations of most people who take up software development though. Those who are genuinely interested in it will learn, and find (or develop if they have to) libraries to do what they seek. They will persist, because that is their nature. If they want a console library, they will find an implementation of ncurses or roll something that is smaller and fit for their purpose.
    Yes, most of them will! But why not to make a simple and easy alternative to ugly consoles/terminals? Then all will find what they need!
    However, those who take up development for other reasons vastly outnumber those who are genuinely interested in learning. Most people who take up some form of development are not truly interested in it. Those people include the ones who find they have to do a programming subject as part of another course (law, mathematics, science, etc etc), moan about the lack of easy to use libraries, try to get someone else to do their work, and often consider developers as some lower form of life. There is certainly room for improvement of C, C++, and their libraries. But don't make the mistake of believing that creating a single library will suddenly increase the popularity of C and C++. Even if your library is a hit among amateur developers.
    Whatever. Everybody deserves a better life. Especially the real developers.Okay, maybe it won't. But if it will help for at least some of the programmers, it will be cool!

    I don't know how it was for you. But the jump from consoles/terminals to real graphics (SDL) was quite big. Why not stay a little longer, mastering the C, while having an opportunity to make cooler stuff and serious projects?

    Today I declare that since this day my only programming objective shall be learning_kit.h! It will be based on SDL, and it will be a good console/terminal alternative AND intro to graphics programming (you will be able to use SDL too, because you will include it before learning_kit.h).

    Going back to lazy foo'.
    Last edited by Mark Miller; 09-22-2013 at 06:18 AM.

  9. #9
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    Each compiled language programmer starts with a console!
    C isn't a compiled language, it's a programming language that can be interpreted/compiled/whatever you can think of.

    If you think stdio has anything to do with consoles then you've misunderstood text streams and should probably go back and learn them.

  10. #10
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Barney McGrew View Post
    C isn't a compiled language, it's a programming language that can be interpreted/compiled/whatever you can think of.
    By that (overly) narrow interpretation, there is no such thing as a compiled language. All languages can technically be interpreted or compiled or whatever.

    The usual definition of a "compiled language", however, is generally "a programming language for which the typical implementation involves a compiler" (underlining mine, for emphasis).

    That definition is inherently fuzzy but C meets the requirement of being a compiled language. The C standards are specifically crafted with a view that most implementations will be (or involve) compilers - and an implementation is characterised as implementing several compilation phases in a defined order. Almost all implementations of C involve a compiler. In fact, the C implementations that are not based on compilers are the exception.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  11. #11
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    It's one thing to say that it's commonly compiled and another to say it's a "compiled language". You're just blurring the line between the language and the implementation whenever you talk about "compiled" and "interpreted" languages -- it's an attribute of the implementation alone, not the language.

  12. #12
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    You're just blurring the line between the language and the implementation whenever you talk about "compiled" and "interpreted" languages -- it's an attribute of the implementation alone, not the language.
    O_o

    No.

    The common interpretation, which grumpy explains, is inherently fuzzy, but you are the one blurring the line.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  13. #13
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    Sorry, but the 'common' interpretation seems to be that a compiled language can only be compiled, and an interpreted language can only be interpreted (clearly it blurs the line). What else would you expect when you use such ridiculous terminology?

    EDIT: And how am I blurring the line between implementation and language? If anything I'm highlighting it.
    Last edited by Barney McGrew; 09-23-2013 at 06:29 AM.

  14. #14
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Barney McGrew View Post
    Sorry, but the 'common' interpretation seems to be that a compiled language can only be compiled, and an interpreted language can only be interpreted (clearly it blurs the line).
    I defy you to name one programming language that can only be compiled or one language that can only be interpreted.

    Whereas it is quite easy to identify programming languages that are typically compiled (C, C++, Fortran, ....) and others that are typically interpreted (perl, python, matlab, etc etc).

    Quote Originally Posted by Barney McGrew View Post
    What else would you expect when you use such ridiculous terminology?
    I would expect people to realise that terms like "compiled language" or "interpreted language" or "scripted language" are used for humans to communicate with humans. Human communication is often ambiguous and imprecise.

    Expecting a precise definition when common usage of a term is imprecise is foolish. And, regardless of your preferences or sensitivity or preciousness, the common definition used in the discipline of computer science for "compiled language" is as I described above.

    And I would expect people to actually read up on the common definition of terms they use, rather than get into a debate on the meaning.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  15. #15
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by satyam0507 View Post
    try this
    if you want to learn mouse handling
    Code:
    #include<dos.h>
    #include<graphics.h>
    NO! don't do this! don't ever do this!

    this is entirely wrong in every way that there is for it to be wrong. this code is for a compiler that is non-standard and obsolete, and it is not portable in any way.

    why do people keep using turbo C++?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-14-2013, 06:41 AM
  2. Need simple C graphics library
    By Sharke in forum C Programming
    Replies: 4
    Last Post: 02-16-2009, 10:25 PM
  3. an easy, portable, python accessible graphics math library
    By ichijoji in forum Game Programming
    Replies: 2
    Last Post: 12-07-2006, 12:10 AM
  4. simple vector-based graphics format?
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 08-25-2006, 11:41 AM
  5. What's a portable graphics library?
    By dwks in forum Game Programming
    Replies: 2
    Last Post: 07-06-2005, 03:13 AM

Tags for this Thread