Archived

This topic is now archived and is closed to further replies.

Khaos

Text output for any system [code]

Recommended Posts

In DOS I know I can write: cout << "hello"; and have it print to my screen. However, am I correct to assume this won''t work for Linux? Or does it? What about MacOSX, or something else? How am I to know what functions work on any system and what work on a specific system? How can I write a text output routine (with no assembly obviously, just pure C++) that will output a given string to the monitor? A simple as possible method to doing this would be appreciated. Theory too, not just code samples. I''d like to know how this works. Can the same method, or any method, be applied to a pixel plotting routine? Sound output? Etc? Can I use simply C++ and nothing else to write a routine that will place a colored pixel on any monitor on any system? I''m sorry for the fact I generally write thoughts as questions. Please point me in the right direction. Thank you all.

Share this post


Link to post
Share on other sites
cout is standard C++ so it will work on any system that has a C++ compiler.

As for plotting pixels or sound, it may be very different from a system to another so you can use a cross-platform library like SDL (http://www.libsdl.org) or write your own functions for every systems you want to support (i suggest the prior)

Hope that helps
Matt

Share this post


Link to post
Share on other sites
Thank you. However, I was not thinking of a commercial library. I would like some help or ideas on rolling my own routine to stick characters in the display memory, that will work on any system or OS.

And also, what''s the difference in binary of the letter "F" displayed on the screen, and a particular red pixel at (17,39)? How can I do similar and place pixels on the screen?

Thanks again.

Share this post


Link to post
Share on other sites
You can''t stick characters in memory on most OSes, because they protect memory (''Protected Mode''). You''ll need to write OS-specific functions and use conditional compilation or something like that to have a different library on each OS that has the same interface.
How you set the display mode and write pixels or text will depend entire on the OS and platform.

Share this post


Link to post
Share on other sites
std::cout is part of the c++ standard library, which is implemented in most new compilers, so that code will work on any OS with a c++ compiler (btw you have to recompile it on the other OS for it to work with that OS). Plotting graphics is much harder to do in an OS independant way, which is why OpenGL and other cross-platform libraries are there.

Share this post


Link to post
Share on other sites
So it''s not possible? You HAVE to have a library per system? In protected mode OSes you cannot simply stick anything in the video display RAM? Is video RAM not accessible or what?

Share this post


Link to post
Share on other sites
quote:
Original post by Khaos
So it''s not possible? You HAVE to have a library per system? In protected mode OSes you cannot simply stick anything in the video display RAM? Is video RAM not accessible or what?


There are higher level access routines for a reason.

If you could get true direct access to lower level hardware functions instead of letting the OS and drivers handle it for you, you would have to write a different set of code for pretty much every piece of hardware there is.

Go with a standard libary.


Or am I reading you wrong?



Far too much time has passed
For us to lament that we were in love.

Share this post


Link to post
Share on other sites
quote:
Original post by Khaos
So it''s not possible? You HAVE to have a library per system? In protected mode OSes you cannot simply stick anything in the video display RAM? Is video RAM not accessible or what?

Precisely. For this reason, languages that do not have standard graphics packages - Java does; C++ does not - are forced to rely on third-party libraries. If you do not wish to use one, then yes, you will have to write different routines for each platform you wish to support.

Share this post


Link to post
Share on other sites
Is the term "platform" used to represent the _processor_, the _operating system_, or both? Is there a generic term for one or the other? If you are writing platform independent code, does that run on any OS or any processor, or both, in other words. What would you call code that could run on 8 bit, 16 bit, 32 bit, or 64 bit processors, from any company (Z80, PIC, x86, etc) on any given OS (if any)? If it could run on ANYTHING, would it be platform independent, or system independent, or what?

I''m sorry to ask stupid questions, but I''d like to have accurate terminology. Thank you.

Share this post


Link to post
Share on other sites
Platform usually refers to the operating system / environment.
e.g. Java Virtual Machines are implemented on an operating system basis, not for different processors.

I think assembler code is different because it is intertwined with the processor, there is no level of abstraction beyong direct opcode translation.

C++ compilers are also written per operating system.

Wizza Wuzza?

Share this post


Link to post
Share on other sites
Platform independant usually means not dependant on OS, but sometimes it means not dependant on OS or processor (which usually means it only uses the standard library, like a basic ''hello world'' program in C). I don''t think it is often used to mean it can run on any processor but only one OS (that usually only happens with linux, so they''ll just say it is for linux).

AFAIK there aren''t any really specific terms. Maybe we should start calling processor independence ''architecture independance'' since thats really what it usually means, and then platform independence could mean only not dependant on the OS.

Share this post


Link to post
Share on other sites