How to put images on the screen?

1

In MSX, you used BASIC to place an image on the screen without leaving command line mode. Today, we can not do this anymore? Without using OpenGL or other APIs, how do I put pixels on the screen? Or a whole picture? Do you have to send it to VRAM? We just learned how to display texts in DOS from the PC.

    
asked by anonymous 14.07.2014 / 08:32

2 answers

1

No - today, normal PCs can not do this. Note that since the VGA specification of the original PC two things happened that prevented you from simply copying a few bytes to a memory region and seeing it on the screen:

1) A fragmentation of the specifications of video modes: after the VGA never mias there was a unified mode of video, which worked on all boards. Each manufacturer, alias each video card, had (and in some ways still has) specific ways of addressing video memory, video modes, etc ... After the video cards exceeded the VGA, and before Windows was the dominant interface for the video, there was a time when each graphics program had to bring the drivers for different video cards into itself.

2) With the greater capacity of computers (PCs), the Operating System began to assume more seriously its role, until then theoretically in the PCs, to abstract the hardware part: the programs no longer had to worry about the board of installed video, and used operating system APIs to draw on the screen. With a call to the system, the program discovers the screen height width in pixels. If the video card did not have all the necessary colors, it was S.O. paper - whether it was Windows, Linux, with the X11 graphics layer, or another system, reduce the number of colors automatically. The operating system also has the role of preventing normal programs from writing to any region of memory or using I / O to reconfigure the video: only the operating system should be able to change the hardware settings - one program should not be able to interfere with other programs which are running.

So that's it - you get the Win 32 API that should allow you to open a full-screen window, and draw in that window. In X11, used in Linux and Unix browsers, you can design in the Root Window. In Linux and other Unixes, without the X11 window system, you could also use framebuffer - that is, fragmentation continues.

A library that appeared after a while, which gives a good idea, simplify everything, and even allow graphics programs that run full screen in both Windows and Linux with or without X11 was SDL - you just need to install it, and its .h files to make code that you draw on the screen.

However - if you go to the SDL site and look for the tutorials, you will see that in C, even using SDL, you have a lot of bureaucracy that you get in the video itself, and you can draw on the screen.

Many years ago I asked myself the same question that you ask now: how do I draw on the screen, something that I only want, without windows of other programs, as it did in the Basic of computers of the 80's?

For me the answer was: using the Python language, and the links of the Python language with the SDL library - this project is called Pygame.

If you install Python from the official site, Pygame - both have installers for windows, you'll be able to write code like this:

import pygame

try:
    pygame.init()
    WIDTH, HEIGHT = pygame.display.list_modes()[0]
    tela = pygame.display.set_mode((1680,1050), pygame.FULLSCREEN)
    #pygame.draw.rect(tela, (255,0,0), (100,100,200,100))
    for y in range(HEIGHT):
        cor = (y % 256, (y + 128) % 256, 255 - y % 256)
        pygame.draw.line(tela, cor, (0,y), (WIDTH,y))
    pygame.event.pump()
    pygame.display.flip()
    pygame.time.delay(10000)
finally:
    pygame.quit()

(this is the full program) Pygame also allows you to upload image files from disk, respond to keyboard and mouse events, and more - see the full documentation on the site.

    
15.07.2014 / 03:15
0

I think the only way will be to use some API or Framework, where you would stop using the text mode terminal to run your applications and run them in the environment prepared by the API.

You can use GTK or Borland C ++ Builder , or APIs such as OpenGL and SDL .

    //Exibindo uma imagem bitmap com SDL
    SDL_Surface *image;
    SDL_Surface *temp;

    temp = SDL_LoadBMP("image.bmp");
    if (temp == NULL) {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 1;
    }

    image = SDL_DisplayFormat(temp);
    SDL_FreeSurface(temp);

I know it's not exactly the answer you'd like, but I do not know any other way.

    
14.07.2014 / 14:19