1

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.

Pattisahusiwa
  • 205
  • 2
  • 8

3 Answers3

2

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.

Christian Hackl
  • 27,051
  • 3
  • 32
  • 62
  • as I mention at previous comment. I just need to create small simulation program. If I've used a third-party libraries. Which the simple one that I can use? – Pattisahusiwa May 02 '14 at 17:36
  • I don't see the relationship between controlling screen resolution and creating a simulation. Look at my answer again, I recommended SDL. – Christian Hackl May 02 '14 at 17:41
  • You're right. I don't need any class to create a screen. I need classes for data structure or to create simulation objects and interaction between them (which I can't use FreeBasic). I just need to know how to create the screen with C++, so I can put any objects. – Pattisahusiwa May 02 '14 at 17:55
  • Perhaps. But the official documentation should always be your first choice. Anyway, your definition of "OOP" is too broad. OOP involves virtual functions. Just using classes doesn't make anything OOP. Look at the standard-container classes of C++ (like `std::vector`) -- they are **not** object-oriented and do **not** have virtual functions. – Christian Hackl May 02 '14 at 21:36
1

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

xlucas
  • 23
  • 6
0

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.

Tim Beaudet
  • 791
  • 7
  • 16
  • Thank you for fast replay. I've create small simulation program with FreeBasic. But, I need to include OOP aspect. So, which libraries that I will choose (just for a small program)? – Pattisahusiwa May 02 '14 at 17:29
  • 1
    @AsisPattisahusiwa: Why do you "need" to include OOP aspects? That's like saying "I need to use a hammer, but I am still looking for a good reason". – Christian Hackl May 02 '14 at 17:36
  • Sorry, I mean, FreeBasic is still under development and not fully support OOP (pure OOP). In my case, I'm stuck to coding complex class relationship with FreeBasic. So, I think I'll use C++ to create the program. But, I don't know how to create simple screen/console with C++ for simulation. I won't using default screen on Linux (or command prompt in windows). I prefer to create new one. – Pattisahusiwa May 02 '14 at 17:47