drawable render issue

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

drawable render issue

roeeNavon
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
Reply | Threaded
Open this post in threaded view
|

Re: drawable render issue

gouessej
Administrator
Hello

Please provide a SSCCE and indicate which versions of JOGL you use (i.e before and after observing a possible regression).
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: drawable render issue

roeeNavon
Hi

this is the SSCCE:
package main;

import javax.swing.JFrame;

import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;

public class MVP implements GLEventListener {
        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);

                MVP mainInstance = new MVP();
                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) {
        }

        @Override
        public void display(GLAutoDrawable drawable) {
                GL2 gl = drawable.getGL().getGL2();

                gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
                gl.glClear(GL2.GL_COLOR_BUFFER_BIT);

                gl.glMatrixMode(GL2.GL_PROJECTION);
                gl.glLoadIdentity();
                gl.glOrtho(0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), 0, -1, 1);

                gl.glMatrixMode(GL2.GL_MODELVIEW);
                gl.glLoadIdentity();

                gl.glBegin(GL2.GL_QUADS);
                gl.glColor3f(1.0f, 0.0f, 0.0f); // Set color to red
                gl.glVertex2f(0, 0); // Bottom-left corner
                gl.glVertex2f(32, 0); // Bottom-right corner
                gl.glVertex2f(32, 32); // Top-right corner
                gl.glVertex2f(0, 32); // Top-left corner
                gl.glEnd();
                gl.glFlush();
        }

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

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

About the versions:
- i am currently use maven, this is the dependcy:
        <groupId>org.jogamp.jogl</groupId>
        <artifactId>jogl-all</artifactId>
        <version>2.3.2</version>
- i was using a jar file before, which i cant find, but it was a way older version
Reply | Threaded
Open this post in threaded view
|

Re: drawable render issue

gouessej
Administrator
Reply | Threaded
Open this post in threaded view
|

Re: drawable render issue

roeeNavon
Thank you very much, it worked perfactly
Reply | Threaded
Open this post in threaded view
|

Re: drawable render issue

gouessej
Administrator
Thank you for the feedback.
Julien Gouesse | Personal blog | Website