void Console::onScreenModeChanged() { #ifndef BF_NO_CONSOLE if(!mConsole) return; OGLCONSOLE_CreateFont(); OGLCONSOLE_Reshape(); #endif }
OGLCONSOLE_Console OGLCONSOLE_Create() { _OGLCONSOLE_Console *console; GLint viewport[4]; /* If font hasn't been created, we create it */ if (!glIsTexture(OGLCONSOLE_glFontHandle)) OGLCONSOLE_CreateFont(); /* Allocate memory for our console */ console = (void*)malloc(sizeof(_OGLCONSOLE_Console)); /* Textual dimensions */ glGetIntegerv(GL_VIEWPORT, viewport); console->textWidth = viewport[2] / CHAR_PIXEL_W; console->textHeight = viewport[3] / CHAR_PIXEL_H; screenWidth = (GLdouble)viewport[2] / (GLdouble)CHAR_PIXEL_W; screenHeight = (GLdouble)viewport[3] / (GLdouble)CHAR_PIXEL_H; console->characterWidth = 1.0 / floor(screenWidth); console->characterHeight = 1.0 / floor(screenHeight); /* Different values have different meanings for xMatrixUse: 0) Do not change the matrix before rendering 1) Upload the console's matrix before rendering 2) Multiply the console's matrix before rendering */ /* Initialize its projection matrix */ console->pMatrixUse = 1; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, screenWidth, 0, screenHeight, -1, 1); glGetDoublev(GL_PROJECTION_MATRIX, console->pMatrix); glPopMatrix(); /* Initialize its modelview matrix */ console->mvMatrixUse = 1; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glScaled(console->textWidth, console->textHeight, 1); glGetDoublev(GL_MODELVIEW_MATRIX, console->mvMatrix); glPopMatrix(); /* Screen and scrollback lines */ /* This is the total number of screen lines in memory (start blank) */ console->maxLines = DEFAULT_MAX_LINES; /* Allocate space for text */ console->lines = (char*)malloc(console->maxLines*(console->textWidth+1)); /* Initialize to empty strings */ memset(console->lines, 0, console->maxLines*(console->textWidth+1)); /* This variable represents whether or not a newline has been left */ console->outputNewline = 0; /* This cursor points to the X pos where console output is next destined */ console->outputCursor = console->lines; /* This cursor points to what line console output is next destined for */ console->lineQueueIndex = 0; /* This cursor points to what line the console view is scrolled to */ console->lineScrollIndex = console->maxLines - console->textHeight + 1; /* Initialize the user's input (command line) */ console->inputLineLength = 0; console->inputCursorPos = 0; console->inputLine[0] = '\0'; /* History lines */ memset(console->history, 0, MAX_INPUT_LENGTH * MAX_HISTORY_COUNT); console->historyQueueIndex = 0; console->historyScrollIndex = -1; /* Callbacks */ console->enterKeyCallback = OGLCONSOLE_DefaultEnterKeyCallback; /* The console starts life invisible */ console->visible = 0; console->transitionComplete = 0; /* If no consoles existed before, we select this one for convenience */ if (!programConsole) programConsole = console; if (!userConsole) userConsole = console; /* Temporary shit */ OGLCONSOLE_Output((void*)console, "Console initialized\n"); OGLCONSOLE_Output((void*)console, "Console display lines:\t\t%i\n", console->textHeight); OGLCONSOLE_Output((void*)console, "Console display columns:\t%i\n", console->textWidth); OGLCONSOLE_Output((void*)console, "Console input length:\t\t%i\n", MAX_INPUT_LENGTH); /* Return the opaque pointer to the programmer */ return (OGLCONSOLE_Console)console; }