PDA

View Full Version : glPixelZoom and glBitMap



Furrage
02-01-2002, 10:24 AM
I've created a textbox and would like to control the zoom of the text. The text is created with glBitMap(...). However, when I use glPixelZoom the text size does not change. The code is below. WinRect is a CRect giving the position of the control in windows coordinates. Left, Right, Top, Bottom, give the coordinates of the window in OpenGL. Can any one tell me what is wrong?

void oglTextBox: http://www.opengl.org/discussion_boards/ubb/biggrin.gifraw() { // Draws text box's contents.
TextMargin = (Top - Bottom) / 20; // Calculate control's internal margin.
TextZoom = WinRect.Height() * 0.9f / 16;
// Calculate zoom factor for text.
glRasterPos2d(Left + TextMargin, Bottom + TextMargin);
// Set raster position.
glPixelZoom(TextZoom, -TextZoom);
// Set zoom factor.
((OpenGLWnd *)((oglSection *)Parent)->Parent)->glPrint(Text);
// Print text.
}

// ------------------------------------------------------------------

void OpenGLWnd::glPrint(CString pString) {
// Prints specified string at specified raster position.
glPushAttrib(GL_LIST_BIT); // Save current list base.
glListBase(FontOffset); // Set offset to start of font set call lists.
glCallLists(pString.GetLength(), GL_UNSIGNED_BYTE, (GLubyte *)pString.GetBuffer(0));
// Draw string via indexed call lists.
glPopAttrib(); // Restore previous list base.
}

// ------------------------------------------------------------------

void OpenGLWnd::BuildFontLists() {
// Builds fonts for window.
char Character; // Character being processed.
int Width, Height; // Width and Height of character being processed.
float OffsetX, OffsetY; // Offset positions of characters being processed.
unsigned char Bitmap[18]; // Bitmap of font.

FILE *InFile = fopen("System.fnt", "r");
// Open font file.
if (InFile != NULL) { // If file opened succesfully...
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// Set packing alignment.
FontOffset = glGenLists(128); // Reserve calllist space for an entire font set.
do { // For each font in file.
fscanf(InFile, "%c %d %d %f %f ", &Character, &Width, &Height, &OffsetX, &OffsetY);
// Read character descriptors.
if (Character == '_')
Character = ' '; // Correct space character.
int Temp = Height * (Width > 8? 2: 1);
// Get size of bitmap.
for (int i = 0; i < Temp; ++i)
fscanf(InFile, "%x ", Bitmap + i);
// Read bitmap.
glNewList(FontOffset + Character, GL_COMPILE);
// Create call list for character.
glBitmap(Width, Height, OffsetX, OffsetY, (GLfloat)(Width + 1), 0.0f, Bitmap);
// Draw the bitmap.
glEndList(); // End the call list.
}
while (Character != ' ');
fclose(InFile); // Close input file.
}
else { // Otherwise note error.
FILE *Log = fopen("Error.log", "a");
// Open error log.
fprintf(Log, "Failed to open font file.\n");
// Note error.
fclose(Log); // Close log.
}
}

Bob
02-01-2002, 11:31 AM
glBitmap is not affected by glPixelZoom, only glDrawPixels and glCopyPixels are. Try glDrawPixels with GL_BITMAP instead.