Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: GL11 quad not showing in LWJGL Display

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    11
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Question [SOLVED] GL11 quad not showing in LWJGL Display

    I'm currently having a problem with my Display not showing my GL11 code to draw text.

    I have created a custom code that generates a rectangle location to display text in png files (a-z,A-Z,1-0,!-?), and I have run into an issue where I have the text generated through the rectangle class through to creating each letter in a separate class/object that creates each letter generated, and continues drawing them back so that they keep displaying.

    Here is the code for the letters (with some parts taken out):

        private static final char alphabet[] = {'A','B','C','D','E','F','G','H','I','J',
                'K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b',
                'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t',
                'u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0'};
        private static final char others[] = {'!','@','#','$','%','^','&','*','(',')','-',
                '_','+','=','[',']','{','}',';',':','\"',',','.','?','\'','<','>','/',' '};
     
        // text search variables
        private int letterIndex;
        private boolean letterFound;    // checks if letter is found
        private boolean otherFound;
        private char letterThis;
     
        // letter draw tools
        private FileInputStream letterFile;
        private Texture letterTex;
     
        // letter position
        private int letterX;
        private int letterY;
        private int letterWidth;
        private int letterScale;
     
        // letter color and opacity variables
        private float red;
        private float green;
        private float blue;
        private float opacity;
     
        // creates a letter texture for drawing
        public LetterList(char letter) {
            letterWidth = 0;
            initOpenGL();
            /************************************************
             *  search alphabet
             ***********************************************/
            letterFound = false;
     
            for (int c = 0; c < alphabet.length; ++c) {
                if (alphabet[c] == letter) {
                    letterFound = true;
                    letterIndex = c;
                    letterThis = alphabet[c];
                    letterWidth = 17+letterScale;
                    // if the letter is wider
                    if (letter == 'M' || letter == 'N' || letter == 'W' || letter == 'w' || letter == '4')
                        letterWidth = 19+letterScale;
                    break;
                }   // if
            }   // for loop
     
            if (letterFound) {
                try {
                    // checks if letter is a capital
                    if (letterIndex < 26)   {
                        letterFile = new FileInputStream("textfonts/cap" + alphabet[letterIndex] + ".png");
                    } else {
                        letterFile = new FileInputStream("textfonts/" + alphabet[letterIndex] + ".png");
                    }   // if - else character search
                    // loads texture
                    letterTex = TextureLoader.getTexture("PNG",letterFile);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }   // try - catch FileNotFoundException
                catch (IOException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }   //
            }   // if letter was found
            else {
                /******************************************************************
                 *  if alphabet is not found, search for special characters
                 ******************************************************************/
                otherFound = false;
     
                for (int c = 0; c < others.length; ++c) {
                    if (others[c] == letter) {
                        otherFound = true;
                        letterIndex = c;
                        letterThis = others[c];
                        letterWidth = 17+letterScale;
                        break;
                    }   // if
                }   // for loop
     
                if (otherFound) {
                    searchSpecialCharacters(others[letterIndex]);
                } else {
                    // throws an exception if character is not in list
                    try {
                        throw new IllegalCharacterException(letter);
                    } catch (IllegalCharacterException e) {
                        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                    }   // try - catch IllegalCharacterException
                }   // else IllegalCharacterException(char)
            }   // else if letter was not found
        }   // LetterList() constructor
     
        /***********************************************************************************
         *
         * @param letter
         * checks for characters that are not found in the alphabet array
         *
         **********************************************************************************/
        private void searchSpecialCharacters(char letter) {
            try {
                switch (letter) {
                    /* goes through case statements to find special characters */
                }   // switch (letter)
                // loads texture
                letterTex = TextureLoader.getTexture("PNG",letterFile);
            } catch (FileNotFoundException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }   // try - catch FileNotFoundException
            catch (IOException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }   // try - catch IOException
        }   // searchSpecialCharacters(char)
     
        public void drawLetter(int x, int y,int color, int fontScale) {
            letterX = x;
            letterY = y;
            letterScale = fontScale;
     
            setColor(color);
            keepDrawingLetters();    // draws letter on creation
     
        }   // drawLetter()
     
        // draws constantly in TextBoxRect after letter is created
        public void keepDrawingLetters() {
            GL11.glColor4f(red, green, blue, opacity);
            // bind logo image to screen
            letterTex.bind();
            // draw quad screen
            GL11.glBegin(GL11.GL_QUADS);
            GL11.glTexCoord2f(0, 0);    // standard texture position
            GL11.glVertex2f(letterX, letterY);
            GL11.glTexCoord2f(1, 0);    // standard texture position
            GL11.glVertex2f(letterX+16+letterScale, letterY);
            GL11.glTexCoord2f(1,1);    // standard texture position
            GL11.glVertex2f(letterX+16+letterScale, letterY+32+letterScale);
            GL11.glTexCoord2f(0, 1);    // standard texture position
            GL11.glVertex2f(letterX, letterY + 32 + letterScale);
            GL11.glEnd();
        }   // keepDrawingLetter()
     
        private void initOpenGL() {
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GL11.glOrtho(0, 800, 0, 600, 1, -1);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
     
            // enable texture mode in 2D
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        }   // initOpenGL()
     
    }   // Letter class

    I solved this problem myself. Apparently I should've called "opacity = 1" in the constructor, because now it works fine.
    Last edited by squeakbox; May 10th, 2012 at 02:47 PM. Reason: Solved the problem myself


Similar Threads

  1. LWJGL texture applying problem
    By DanielJamesCollier in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 16th, 2012, 01:45 PM
  2. [SOLVED] (LWJGL)openGL arraylist rendering problem
    By DanielJamesCollier in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 11th, 2012, 02:21 PM
  3. Replies: 3
    Last Post: March 6th, 2012, 03:50 AM
  4. [SOLVED] Problem with OpenGL via LWJGL
    By paulo.carabuena in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 6th, 2011, 02:52 PM
  5. showing page
    By ighor10 in forum Java Theory & Questions
    Replies: 1
    Last Post: August 26th, 2010, 08:52 AM