Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8108529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:08:22+00:00 2026-06-06T01:08:22+00:00

At the moment I not too sure where my problem is. I can draw

  • 0

At the moment I not too sure where my problem is. I can draw loaded images as textures no problem, however when I try to generate a bitmap with a char on it I just get a black box.

I am confident that the problem is when I generate and upload the texture.

Here is the method for that; the top section of the if statement just draws an texture of a image loaded from file (res/texture.jpg) and that draws perfectly. And the else part of the if statement will try to generate and upload a texture with the char (variable char enter) on.

output

Source Code, I will add shaders and more of the C++ if needed but they work fine for the image.

    void uploadTexture()
    {
        if(enter=='/'){

            // Draw the image.
            GLenum imageFormat;
            glimg::SingleImage image = glimg::loaders::stb::LoadFromFile("res/texture.jpg")->GetImage(0,0,0);
            glimg::OpenGLPixelTransferParams params =  glimg::GetUploadFormatType(image.GetFormat(), 0);
            imageFormat = glimg::GetInternalFormat(image.GetFormat(),0);

            glGenTextures(1,&textureBufferObject);
            glBindTexture(GL_TEXTURE_2D, textureBufferObject);

            glimg::Dimensions dimensions = image.GetDimensions();
            cout << "Texture dimensions w "<< dimensions.width << endl;
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, dimensions.width, dimensions.height, 0, params.format, params.type, image.GetImageData());
        }else
        {
            // Draw the char useing the FreeType Lib
            FT_Init_FreeType(&ft);
            FT_New_Face(ft, "arial.ttf", 0, &face);
            FT_Set_Pixel_Sizes(face, 0, 48);

            FT_GlyphSlot g = face->glyph;


            glGenTextures(1,&textureBufferObject);
            glBindTexture(GL_TEXTURE_2D, textureBufferObject);

            glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            FT_Load_Char(face, enter, FT_LOAD_RENDER);
            FT_Bitmap theBitmap = g->bitmap;

            int BitmapWidth = g->bitmap.width;
            int BitmapHeight = g->bitmap.rows;



            cout << "draw char - " << enter << endl;
            cout << "g->bitmap.width - " << g->bitmap.width << endl;
            cout << "g->bitmap.rows - " << g->bitmap.rows << endl;

            int TextureWidth =roundUpToNextPowerOfTwo(g->bitmap.width);
            int TextureHeight =roundUpToNextPowerOfTwo(g->bitmap.rows);

            cout << "texture width x height - " << TextureWidth <<" x " << TextureHeight << endl;

            GLubyte* TextureBuffer = new GLubyte[ TextureWidth * TextureWidth ];
            for(int j = 0; j < TextureHeight; ++j)
            {
                for(int i = 0; i < TextureWidth; ++i)
                {
                    TextureBuffer[ j*TextureWidth + i ] = (j >= BitmapHeight || i >= BitmapWidth ? 0 : g->bitmap.buffer[ j*BitmapWidth + i ]);
                }
            }

            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, TextureWidth, TextureHeight, 0, GL_RGB8, GL_UNSIGNED_BYTE, TextureBuffer);
        }

    } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:08:23+00:00Added an answer on June 6, 2026 at 1:08 am

    I’m not sure about the OpenGL part, but your algorithm to process FT bitmap is not correct. The number of bytes of each row in FT bitmap is bitmap->pitch. The number of each pixel also depends on which render mode your are loading the character. For example, if bitmap->pixel_mode is FT_PIXEL_MODE_LCD, each pixel is encoded as 3 bytes, in order of R, G, B and the values are actually the alpha mask value, while if the pixel mode is FT_PIXEL_MODE_GRAY, each pixel is 1 byte and the values are the gray level.

    Take a look at http://freetype.sourceforge.net/freetype2/docs/reference/ft2-basic_types.html#FT_Bitmap

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not too sure if the title to this actually explains what I really need
I hope the question is not too unspecific. At the moment, I am trying
Im not sure if this is possible, but at the moment I have a
Apologies on the heading, not sure I can explain this easily/well. I've inherited a
So at this moment (but most likely not for long) Reddit, Meetup, Fark, LinkedIn,
Since foreign keys are not supported by partitioned mySQL databases for the moment, I
I ask this question because I'm not able to test it at the moment.
So I am doing this as a learning moment and I'm not afraid to
My delete method is not working, here is what is happening at the moment.
I have a delete issue at the moment. We do not have permission to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.