【问题标题】:Allegro 5 & C++ - Creating a fullscreen console?Allegro 5 & C++ - 创建一个全屏控制台?
【发布时间】:2013-06-13 22:27:31
【问题描述】:

好吧,这是我的主要目标:获得一个全屏、非窗口的控制台程序(打开时看起来像 DOS 操作系统)。我已经定义了ALLEGRO_USE_CONSOLE 和所有这些东西。这是我要查看的完整代码:

#define _WIN32_WINNT 0x0500
#define ALLEGRO_USE_CONSOLE

#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <string>
#include <time.h>
#include "include/allegro.h"

using namespace std;

void SetColor(unsigned short hColor) {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), hColor);
}

void Dots() {
    int i = 1;
    while (i <= 3) {
        cout << ".";
        Sleep(750);
        i++;
    }
}

void ClearConsoleScreen() {
    HANDLE                     hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    DWORD                      count;
    DWORD                      cellCount;
    COORD                      homeCoords = { 0, 0 };

    if (hStdOut == INVALID_HANDLE_VALUE) return;

    /* Get the number of cells in the current buffer */
    if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
    cellCount = csbi.dwSize.X *csbi.dwSize.Y;

    /* Fill the entire buffer with spaces */
    if (!FillConsoleOutputCharacter(
            hStdOut,
            (TCHAR) ' ',
            cellCount,
            homeCoords,
            &count
        )
    ) return;

  /* Fill the entire buffer with the current colors and attributes */
    if (!FillConsoleOutputAttribute(
        hStdOut,
        csbi.wAttributes,
        cellCount,
        homeCoords,
        &count
        )
    ) return;

    /* Move the cursor home */
    SetConsoleCursorPosition( hStdOut, homeCoords );
}

int main() {
    ALLEGRO_DISPLAY       *display = NULL;
    ALLEGRO_DISPLAY_MODE   disp_data;

    al_init(); // I'm not checking the return value for simplicity.

    al_get_display_mode(al_get_num_display_modes() - 1, &disp_data);

    al_set_new_display_flags(ALLEGRO_FULLSCREEN);
    display = al_create_display(disp_data.width, disp_data.height);

    al_rest(3);
    al_destroy_display(display);
}

那么我到底需要做什么才能使控制台全屏(非窗口和无边框)并能够使用cout 等?我也在运行Win7。

【问题讨论】:

  • 是的,我在上面的代码中确实有很多不需要的标头,但是如果我可以让这段代码像我希望的那样工作,就会使用这些标头。

标签: c++ windows-7 mingw codeblocks allegro5


【解决方案1】:

ALLEGRO_USE_CONSOLE 只是告诉 Allegro 您计划使用控制台窗口运行程序;您仍然必须在链接器选项中将子系统设置为“控制台”。 Allegro 与创建控制台窗口无关。

现在,如果您只是想让控制台在 Windows 上全屏显示,可以使用 SetConsoleDisplayMode,但这与 Allegro 无关。您不能使用 Allegro 的绘图 API,因为没有 Direct3D 或 OpenGL 上下文可供使用。

编辑:似乎上述功能不再适用于现代版本的 Windows...

使用控制台是非常特定于平台的,这也是allegro_native_dialog 存在的部分原因。但是没有办法让它进入全屏模式。

如果您想要跨平台功能,您可以使用 Allegro 的绘图 API 创建自己的模拟控制台,但这将是一项艰巨的任务。

通常,想要控制台应用程序的人并不关心它的外观,只关心您输入的数据是否正确。

【讨论】:

  • 那么基本上没有简单的方法可以让Windows 7上的控制台全屏?唯一可能的方法是在 OpenGL、Allegro 或 SDL 中模拟控制台?太糟糕了。好的,谢谢你的信息。我想我现在会坚持使用常规控制台窗口。
猜你喜欢
  • 2011-05-24
  • 2014-01-02
  • 2013-06-12
  • 1970-01-01
  • 2010-11-18
  • 2015-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多