Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Bitmap font trouble

This topic is 4594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a temp fix for this but I wanna know what's going on. I load my bitmap font and it works fine. I created my own textboxes scrollbars, etc. for my game engine. Everything else works fine, except when I make my listbox. Now the listbox contains a scrollbar, a quad, and then the list of current items shown, and a quad for each of the items (for selected, current item, disabled, etc). When i add 3 items, all is well. When i add 4 items and up, my bitmap font messes up. All the letters and numbers are wrong. "Listbox: 2" becomes "Khrsanw92". It shifts every character left one. If I add an item, but don't put the text into the listbox text field (i've tried char* and string for the text field), the main bitmap font prints shifted to the right 1, and the mask bitmap font prints shifted to the left 1. I don't know how i'm manipulating the font/print command since i'm not calling anything with my listbox yet. All it does is add items, not print commands at all. My classes are being created just fine, and can be read fine. But printing text after add the items becomes messed up. Suggestions? (the temp fix btw, is to Kill the Font and Reload it.) Basically
class EntryItem
          string text;
          int iValue;
          float fValue;
          int entryType;
          bool disable;
          bool selected;
class listbox
     EntryItem *entries;
     int totalEntries;
     void Add_Item();
     void Add_Item(char *text);
     void Equal_EntryItem(EntryItem *b1, EntryItem *b2);

void Listbox::Equal_EntryItem(EntryItem *b1, EntryItem *b2)
     b1->text = b2->text;
     b1->iValue = b2->iValue;
     b1->fValue = b2->fValue;
     b1->entryType = b2->entryType;
     b1->disable = b2->disable;
     b1->selected = b2->selected;
void Listbox::Add_Item()
     EntryItem *temp;
     temp = 0;
     temp = new EntryItem[3];
     delete [] temp;
     int count;
     if (entries && totalEntries > 0)
          temp = new EntryItem[totalEntries];
          for (count = 0; count < totalEntries; count++)
               Equal_EntryItem(&temp[count], &entries[count]);
          delete [] entries;          
          entries = 0;
          totalEntries = 0;
     entries = 0;
     entries = new EntryItem[totalEntries];     
     if (temp)
          for (count = 0; count < totalEntries - 1; count++)
               Equal_EntryItem(&entries[count], &temp[count]);
          delete [] temp;
     temp = 0;
void Listbox::Add_Item(char *theText)
     int count;
     int error;     
     count = totalEntries - 1;     
     entries[count].text = theText;

[EDIT] I have done quite the searching for an answer, although none obtained. Some might have had one but ppl kept writing bump instead of an answer. The reason this is in Opengl and not a c++ one is that the only part messing up is the openGL part of it. [Edited by - ARelativeBelief on April 19, 2006 10:51:38 PM]

Share this post

Link to post
Share on other sites
Well I'm beginning to understand a little of what's going on. My listbox class isn't the only thing to cause the problem. When i type too much text into my textbox the same thing happens. My textbox is using a std::string.
I decided to run a test, I textured a quad with my whole font. If i don't add any items to my listbox class and don't type any text, it shows up fine and all the text on the screen is fine. After typing like 8 letters all the letters are wrong. My quad with the whole font is now a different texture.
I'm confused. Am I pushing the memory around somehow? This is really puzzling me. Any help would be appreciated. I'm entering unknown memory managing with opengl.

[edit]This is my 2d component class. It holds all the texture ID's and controls

#include "Quad.h"
#include "Button.h"
#include "Textbox.h"
#include "Texture.h"
#include "TexturePoint.h"
#include "FontBMP.h"
#include "Vector2i.h"
#include "Constants.h"
#include "Screens.h"
#include "Menus.h"
#include "string"
#include "ScrollBar.h"
#include "Listbox.h"
#include "EntryItem.h"

using namespace std;

#ifndef Component2d_h
#define Component2d_h

struct ControlOrder
int type;
int index;

class Component2d
int Check_Mouse(int mouseX, int mouseY, int buttonLR, int previousX, int previousY);
void Click_Held(int mouseX, int mouseY, int buttonLR, int theControl);
int Click_Up(int mouseX, int mouseY, int buttonLR, int theControl);
Button *button;
Textbox *textbox;
ScrollBar *scrollBar;
Listbox *listbox;
ControlOrder *controlOrder;
Texture *texture;
FontBMP fonts;
Screens screen;
Menus menuBar;
int focus;
int failure;
int totalButton;
int totalTextbox;
int totalControlOrder;
int totalTexture;
int totalScrollBar;
int totalListbox;
void Equal_Quad(Quad *b1, Quad *b2);
void Equal_Button(Button *b1, Button *b2);
void Equal_Textbox(Textbox *b1, Textbox *b2);
void Equal_ScrollBar(ScrollBar *b1, ScrollBar *b2);
void Equal_Listbox(Listbox *b1, Listbox *b2);
void KeyPress(char *theBuff);
void Focus(int theControl);
int Add_Control_Var();
int Add_Control(int theType);
int Remove_Control(int theType, int theIndex);
int Add_Texture(LPTSTR aFile, char *aName);
//int Remove_Texture(int theTexture);
void Remove_All_Texture();
int Init();
int Zero_Component2d();
int Draw_Controls();
int Draw_Controls_No_Init();

Share this post

Link to post
Share on other sites
Ok, I solve my problem. No idea what I did wrong, but I changed everything over to using vectors for my arrays. Now my only issue with std::string, but i'm finding ways around the error.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!