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 528909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:02:09+00:00 2026-05-13T09:02:09+00:00

Exposition: I’m writting an OpenGL app in Java via JOGL. The built in fonts

  • 0

Exposition:

I’m writting an OpenGL app in Java via JOGL. The built in fonts with GLUT are very basic. I want to be able to take a Java Font, render all the characters in it to a 2D array of bytes (a greyscale image representing the characters), which I can then load as a texture in OpenGL.

Problem:

I can load the textures in OpenGL; I can use JOGL. My only problem is going from the “Font java cn read” –> “2D greyscale image of all the characters step”. What functions / libraries should I be using?

  • 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-05-13T09:02:10+00:00Added an answer on May 13, 2026 at 9:02 am

    I’m not sure I quite understand what you’re looking for. I think what you want is some code that will generate grayscale bitmap images of a given size for every glyph in a font.

    There isn’t a way (that I am aware of anyway) to get all the glyphs a font supports (oddly, you can get the number of glyphs… so yeah, I may just be missing something, bah). However, you can get glyph metrics for given characters quite easily.

    Something along these lines should work for you.

    HashMap<int[], Rectangle2D> generateGlyphs(int fontSize, String characters, Font font){
      HashMap<int[], Rectangle2D> ret = new HashMap<int[], Rectangle>();
      FontRenderContext rendCont = new FontRenderContext(null, true, true);
    
      for(int i = 0; i < characters.length; i++){
        Rectangle2D bounds = font.getStringBounds(characters.substring(i, 1), rendCont);
        BufferedImage bi = new BufferedImage((int)bounds.getWidth(), (int)bounds.getHeight(), BufferedImage.TYPE_INT_GRAY);
    
        Graphics g = bi.getGraphcs();
        g.setFont(font);
        g.drawString(characters.substring(i, 1), 0, (int)bounds.getHeight());
    
       ret.put(bi.getData().getPixels(0, 0, (int)bounds.getWidth(), (int)bounds.getHeight()), bounds);
      }
    
      return ret;
    }
    

    Note that I’m clipping rather than rounding in some places, which could potentially be an issue.

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

Sidebar

Related Questions

No related questions found

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.