Login  Register

drawable render issue

Posted by roeeNavon on Mar 10, 2024; 6:46am
URL: https://forum.jogamp.org/drawable-render-issue-tp4043384.html

i am trying to render images and text to screen, all configured to be at 0,0 but this is the results

and this is my code:
public class Main implements GLEventListener {
        private TextRenderer textRenderer;
        private static final int WIN_WIDTH = 600;
    private static final int WIN_HEIGHT = 400;

    public static void main(String[] args) {
        JFrame frame = new JFrame("JOGL Application");
        GLProfile profile = GLProfile.getDefault();
        GLCapabilities capabilities = new GLCapabilities(profile);
        GLCanvas canvas = new GLCanvas(capabilities);

        Main mainInstance = new Main();
        canvas.addGLEventListener(mainInstance);

        frame.getContentPane().add(canvas);
        frame.setSize(WIN_WIDTH, WIN_HEIGHT);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }

    @Override
    public void init(GLAutoDrawable drawable) {
        textRenderer = new TextRenderer(new java.awt.Font("Arial", java.awt.Font.BOLD, 12));
        textRenderer.setColor(1.0f, 1.0f, 1.0f, 1.0f); // White color
    }

    @Override
    public void display(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();
       
        // Clear the color buffer with a black background
        gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
       
        // Enable blending for transparency
        gl.glEnable(GL2.GL_BLEND);
        gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
       
        // Set up the orthographic projection matrix
        gl.glMatrixMode(GL2.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrtho(0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), 0, -1, 1);
       
        // Switch back to the modelview matrix
        gl.glMatrixMode(GL2.GL_MODELVIEW);
        gl.glLoadIdentity();
       
        // Render the sprite using SpriteRenderer.renderSprite method
        SpriteRenderer.renderSprite(Assets.image, gl, drawable, 0, 0, 64, 64);
    }

    @Override
    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        // Unused
    }

    @Override
    public void dispose(GLAutoDrawable drawable) {
        // Unused
    }
}

it worked once, but then i upgraded my jogl version and this bug started