Draw functions stopped working

Started by Danko, December 27, 2011, 22:20:43

Previous topic - Next topic

Danko

Hello everyone,

I'm currently working on a small application using LWJGL as graphic library and Slick as utility library. I noticed, that drawing with native functions, like using glBegin() with GL_LINES or GL_QUADS stopped working after I had loaded a texture and a font using Slick. When commenting the related lines out everything works and it renders the screen as it is supposed to do, it still renders the texture though, sadly in black whereas the source image is colored, I have copied most functions from an already existing project and I honestly don't find the problem.

Code: initialization
            Display.setDisplayMode(windowDimension);
            Display.setTitle(StaticProperties.gameName + " " + StaticProperties.gameVersion);
            Display.setResizable(false);
            Display.setVSyncEnabled(true);
            Display.create();
            
            Keyboard.create();
            Mouse.create();
            
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glOrtho(0, StaticProperties.windowWidth, StaticProperties.windowHeight, 0, 1, -1);
            glViewport(0, 0, StaticProperties.windowWidth, StaticProperties.windowHeight);
            glShadeModel(GL_SMOOTH);
            glMatrixMode(GL_MODELVIEW);
            
            glEnable(GL_TEXTURE_2D);
            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            
            spriteHolder.loadTextures();
            
            wurmicsFont = new Text("resource/font/wurmics.ttf", 24, false);
            hthFont = new Text("resource/font/hth.ttf", 24, false);


Code: texture loader
private int loadTexture(String resourcePath) {
    try {
        int textureId;

        Texture texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(resourcePath));
        textureId = texture.getTextureID();
            
        spriteMap.put(textureId, texture);
        return textureId;
    }
        
    catch (Exception exception) {
        exception.printStackTrace();
    }
        
    return INVALID_TEXTURE_ID;
}


Code: Font loading
public Text(String fontName, int fontSize, boolean isCustomLoad) {
        try {
            InputStream inputStream = ResourceLoader.getResourceAsStream(fontName);
            Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream);
            
            awtFont = awtFont.deriveFont(fontSize);
            
            trueTypeFont = new TrueTypeFont(awtFont, false);
        }
        
        catch (Exception exception) {
            exception.printStackTrace();
        }
    }


Code: Example rendering function
int tileTextureId = Game.instance.spriteHolder.getTextureId(SpriteType.Head);
        
        glLoadIdentity();
        glColor3f(0.0F, 0.0F, 0.0F);
        glTranslatef(xPosition, yPosition, 0.0F);
        
        glBegin(GL_QUADS);
        glVertex2f(0.0F, 0.0F);
        glVertex2f(0.0F, boxHeight);
        glVertex2f(boxWidth, boxHeight);
        glVertex2f(boxWidth, 0.0F);
        glEnd();
        
        Game.instance.spriteHolder.getTexture(tileTextureId).bind();
        
        glLoadIdentity();
        glTranslatef(xPosition + 20.0F, yPosition + 20.0F, 0.0F);
        
        glBegin(GL_QUADS);
        glTexCoord2f(0.0F, 0.0F);
        glVertex2f(0.0F, 0.0F);
        glTexCoord2f(1.0F, 0.0F);
        glVertex2f(150.0F, 0.0F);
        glTexCoord2f(1.0F, 1.0F);
        glVertex2f(150.0F, 75.0F);
        glTexCoord2f(0.0F, 1.0F);
        glVertex2f(0.0F, 75.0F);
        glEnd();
        
        Color.black.bind();
        glLoadIdentity();


All resource paths and variable names are correct and work, just in case someone reckons that to be the problem.

Matthias

If you want to render colored primitives without texture then you need disable texturing.

Danko

Yes, you are right, I just had to use glDisable(GL_TEXTURE_2D) before rendering primitives, problem solved, thank you.