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

  • SEARCH
  • Home
  • 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 7733449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:59:31+00:00 2026-06-01T06:59:31+00:00

I’ve searched around quite a bit for ways to do this and I finally

  • 0

I’ve searched around quite a bit for ways to do this and I finally decided to just write text by loading it from a bitmap image. This is my first go at loading separate regions of an image and using a bitmap, so I know I have some mistakes in my algorithm. (Some major ones I would bet) but I did it the best way I could think of how. IF someone would tell me what I’m doing wrong and point me in the right direction to figuring this out that would be great. From what I can tell when I send the information into the render it is correct, I get the right character and the right x,y position to translate it too, and the texture is loading just fine as well. I just can’t seem to figure out why I’m not getting the right part of the image for the letter, nothing is showing up.

Here is my code.

public class StringText {

private ArrayList<TextChar> fontChar;
private final int CHAR_SIZE = 8;
private final int MARGINE = 1;
private Texture fontTexture;
private String lower;
private String upper;
private String symb;
private final int IMAGE_SIZE  = 256;


public StringText(){
    lower = "abcdefghijklmnopqrstuvwxyz";
    upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    symb = ".,?:*!+-() ";
    fontChar = new ArrayList<TextChar>();
    readInFont("font");
    populateCheck();
}

public void drawText(String ts, int x, int y, float red, float green, float blue){
    for(int a = 0; a < ts.length(); a++){
        for(int b = 0; b < fontChar.size(); b++)
        if(fontChar.get(b).getChar == ts.charAt(a))
            render(fontChar.get(b),a, x, y, red, green, blue);
    }
}

private void populateCheck(){
    int charX = 0;
    int charY = 0;
    for(int x = 0;  x < lower.length(); x++){
        TextChar t = new TextChar(lower.charAt(x), charX, -8);
        fontChar.add(t);
        charX += CHAR_SIZE;
    }
    charX = 0;
    for(int x = 0; x < upper.length(); x++){
        TextChar t = new TextChar (upper.charAt(x), charX, -16);
        fontChar.add(t);
        charX += CHAR_SIZE;
    }
    charX = 0;
    for(int x = 0; x < symb.length(); x++){
        TextChar t = new TextChar(symb.charAt(x), charX, -24);
        fontChar.add(t);
        charX += CHAR_SIZE;
    }
}

private void render(TextChar textChar, int current, int x, int y, float red, float green, float blue){
    int inc = current * (CHAR_SIZE + MARGINE);
    glLoadIdentity();
    glTranslatef(x + inc,y,0f);
    glColor3f(red, green, blue);
    glScalef(1.0f, -1.0f, 1.0f);
    fontTexture.bind();
    System.out.println("Letter Position: " + (x+inc) + ", " + y + " Character: " + textChar.getChar);


    float x0 = textChar.x/IMAGE_SIZE;
    float y0 = textChar.y/IMAGE_SIZE;
    float x1 = (textChar.x + CHAR_SIZE)/IMAGE_SIZE;
    float y1 = (textChar.y - CHAR_SIZE)/IMAGE_SIZE;

    glBegin(GL_QUADS);
        glTexCoord2f( x0, -y0); glVertex2f(0,0);
        glTexCoord2f(x1,-y0); glVertex2f(IMAGE_SIZE,0);
        glTexCoord2f(x1,-y1); glVertex2f(IMAGE_SIZE, IMAGE_SIZE);
        glTexCoord2f(x0,-y1); glVertex2f(0,IMAGE_SIZE);
    glEnd();
}

private void readInFont(String s){
    try {
        fontTexture = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/font/"+ s +".png")));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

private class TextChar{
    int x,y;
    char getChar;
    public TextChar(char s, int xa, int ya){
        x = xa;
        y = ya;
        getChar = s;
    }
}

}

  • 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-01T06:59:33+00:00Added an answer on June 1, 2026 at 6:59 am

    I figured out a better way to do it than this by using an ASCII bitmap.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.