Domanda

With FreeBasic I can create and open a new screen with a function ScreenRes. For example,

#include "fbgfx.bi"

ScreenRes 640, 480, 32

Sleep()

will create a 640 x 480 screen with depth 32.

So, is there any function in C++ that equivalent with that?

Note: I'm using Ubuntu 14.04. I'm prefer cross-platform or linux-based functions than a windows-based.

È stato utile?

Soluzione

No, there is not. C++ itself is a very pure language and contains only basic functionality (e.g. generic lists, sorting algorithms, strings or memory-management tools). I don't know FreeBasic, but judging from your question, it seems to be one of those languages which have a lot of specific high-level functionality already included in them. This can be a curse or a virtue, depending on your requirements.

If you need graphics in C++, then you "must" (==> curse) or "can" (==> virtue) use a 3rd-party library which fits exactly your needs. For complete pixel-wise control over the screen, consider SDL.

Altri suggerimenti

As the guys said, there is no such thing in C/C++. To do graphics in C, you need to rely on an external library, which you probably don't want to do, since you're saying you prefer "linux-based functions".

Unfortunately, accessing graphics in Linux only through the libraries that come with the OS is very complex and your program wouldn't be portable to other systems. (If you want to do this anyway, you may want to read about the Linux linear framebuffer or about X).

What I think is the closest solution to what you ask is that you get a small library with simple primitives. I think SVGALib is something like that: http://www.svgalib.org/

I haven't used it, but for what I read, it's kind of similar to the graphics.h that used to come with Turbo/Borland C++. For example, you can do this with SVGALib:

#include <stdlib.h>
#include <vga.h>

int main(void)
{
   vga_init();
   vga_setmode(G320x200x256);
   vga_setcolor(4);
   vga_drawpixel(10, 10);

   sleep(5);
   vga_setmode(TEXT);

   return EXIT_SUCCESS;
}

There you can see how to set a mode. I'm pretty sure it'll support 32bits too :)

I'm not so familiar with Linux, however, things of this nature are not that easy in C++ as C++ is a language and it doesn't know what a "screen" is. There are libraries and frameworks that can help you, like SDL, SFML, and many more which will get you pointed in the correct direction.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top