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 2 of 2

Thread: Problem with OpenGL via LWJGL

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with OpenGL via LWJGL

    hi guys.. first and foremost.. this is my first post, idk if this is the right section.. but here it goes..

    i'm working on a project.. it's a game programming library, focusing on portability in the java environment.. i am currently working on the display function.. as a system dependency, J2SE can use OpenGL for its graphics functionalities such as display or for rendering, etc..

    i'm not doing things from scratch, my adviser (now on temporary leave) told me to look for some open source libraries in the Internet to lighten my load.. I found LWJGL which provides classes and interface for OpenGL.. so i use it for the J2SE OpenGL module of my library..

    the program i've written so far works perfectly for basic polygon rendering in both OpenGL and native hardware accelerated graphics.. however, when I proceed to image rendering there seems to be some problem..

    actual.jpgexpected.jpg

    the image above shows the output after i run my program.. the OpenGL rendering is the one with the suicune behind the red translucent rectangle..

    here is the code for initializing LWJGL

     
    	private void initGL() {
    		GL11.glEnable(GL11.GL_TEXTURE_2D);
    		GL11.glDisable(GL11.GL_DEPTH_TEST);
     
    		GL11.glMatrixMode(GL11.GL_PROJECTION);
    		GL11.glLoadIdentity();
     
    		GL11.glOrtho(0, this.size.width, this.size.height, 0, -1, 1);
     
    		GL11.glEnable(GL11.GL_BLEND);
    		GL11.glClearColor(0, 0, 0, 0);
     
    		GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    	}
     
    	private void initGraphics() {
    		try {
    			DisplayMode best = (this.isFullscreen) ? 
    					this.getBestDisplayMode(size) : new DisplayMode(
    							this.size.width, this.size.height);
     
    			if(best == null) {
    				throw new Exception();
    			}
     
    			org.lwjgl.opengl.Display.setDisplayMode(best);
    		} catch(Exception e) {
     
    		}
     
    		try {
    			org.lwjgl.opengl.Display.setTitle(this.title);
    			org.lwjgl.opengl.Display.setFullscreen(this.isFullscreen);
    			org.lwjgl.opengl.Display.setVSyncEnabled(this.usingVsync);
    			org.lwjgl.opengl.Display.create();
    		} catch(Exception e) {
     
    		}
    	}

    and here is the code for rendering the image:

        public boolean drawImage(Image img,
    							 int x, int y, int width, int height,
    							 ImageObserver observer) {
    		startPainting();
     
     
    		GL11.glPushMatrix();
     
    	    Texture texture = textureLoader.getTexture((BufferedImage) img);
    		texture.bind();
     
    		GL11.glTranslatef(x, y, 0);
     
    		GL11.glBegin(GL11.GL_QUADS);
    			GL11.glTexCoord2f(0, 0);
    			GL11.glVertex2f(0, 0);
     
    			GL11.glTexCoord2f(0, texture.getHeight());
    			GL11.glVertex2f(0, height);
     
    			GL11.glTexCoord2f(texture.getWidth(), texture.getHeight());
    			GL11.glVertex2f(width, height);
     
    			GL11.glTexCoord2f(texture.getWidth(), 0);
    			GL11.glVertex2f(width, 0);
    		GL11.glEnd();
     
    		GL11.glPopMatrix();
     
     
    		endPainting();
     
    	    return true;
        }

    oh btw here is how i called the rendering routine:

    	public void render(Graphics g) {
    		g.setColor(Color.RED);
    		g.fillRect(0, 0, 640, 480);
    		image.render(g, 0, 0);
    	}

    any help to make the OpenGL rendered image look exactly like the second image? thanks in advance


  2. #2
    Junior Member
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with OpenGL via LWJGL

    nevermind guys, someone already told me what to do.. thanks anyway

Similar Threads

  1. Replies: 3
    Last Post: January 5th, 2012, 01:44 AM
  2. about making rubick with openGL
    By crimx in forum Java Theory & Questions
    Replies: 0
    Last Post: December 6th, 2011, 10:20 AM
  3. OpenGL Texture won't draw
    By nivangerow in forum Android Development
    Replies: 1
    Last Post: November 26th, 2011, 06:03 AM
  4. 3D picking in opengl
    By eshvartz in forum Java Theory & Questions
    Replies: 0
    Last Post: November 21st, 2011, 03:52 AM