graphics, black box

ok for starters sorry I have been making tons of threads lately.

I try this tut out http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/opengl/basicopengl

I get a black window that is full screen(still with menu though). I cant seem to get it to shrink. also is this supposed to be black. cause if so ok but otherwaise that is a problem.

Ah that tutorial is just out of date as of LWJGL 2.0… LWJGL 1.x used to set up the display such that it had normal "pixel " coordinates orthographically projected onto the entire display - a bit like Java2D - but LWJGL 2.0 doesn’t do that any more, you need to stick in another line of initialisation to do it:


GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, displaywidth, 0, displayheight, -1.0f, 1.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);

Do that once only, before the main loop starts but after initing the display.

Cas :slight_smile:

that did not change anything. or was it supposed to?

here is a screen shot of what happens for me.

could yo post one of what ahppens for you?

This example is 2D drawing. You have to specify the 2D space, I use GLU for that :

GL11.glViewport(0,0,Display.getDisplayMode().getWidth(),Display.getDisplayMode().getHeight());
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight());
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();

When you draw your quads, you didn’t specify the color (before the glBegin) :

GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

what is the import for GLU? also can someone pls jsut post what it is supposed to look like. cause there may be nothing wrong with the way it is right now,=.

i think GLU in a new packate location

import org.lwjgl.util.glu.GLU;

ok so i dont think that I have glu. cause I got the nehe tutorials. It looks at org.lwjgl.opengl.glu.GLU;

it cant find it :/.

yup thats correct in addition to the lwjgl.jar you’ll have to add lwjgl_util.jar to your build path to use GLU

I have though. that is the problem. I have added all of them. here is a list of the stuff I got ont here.

jinput.jar
lwjgl.jar
lwjgl_util.jar
lwjgl_util_apllet.jar

are you using an IDE like Eclipse?

yes I use and IDE but I use BLUEJ

What version of lwjgl are you using ?

I confirm that GLU in lwjgl 2 is in lwjgl_util.jar with the import org.lwjgl.util.glu.GLU.
I was using it with lwjgl 1 but with a different import (I don’t remember it).

I have LWJGL 2.0. I got it like alst week. what is the import cause maybe it is wrong in the tutorail.

HAHAHA I found the class hierarchy fo glu. it is actually at org.lwjgl.util.glu.GLU. WOOOT. It all works now. YES! I love google.

ok enough me ranting. thank you allf or your help, I am very thankful.

That was harder than it ought to be…

::slight_smile:

WWWHHHHYYYYYY!!! GRRRR. COMON I WENT THROUGH SO MUCH TROUBLE.

oh yeah btw lwjgl is easy once youg et eh hang of it. i am already at 3d objects. also where is the devil thing, I will google it.

Devil has been removed from lwjgl and is no longer part for lwjgl 2.0+ as a replacement you can use Slick-Util’s it can be found at http://slick.cokeandcode.com/downloads/util/ with javadoc at http://slick.cokeandcode.com/javadoc-util/ the download contains working examples on how to use it.

oops, didnt relise you found it.

you found it before me. How am Is upposed to do texture wrapping. cause the library doesnt include Devil, wich is what Nehe uses.

What I use, it’s not perfect but it work for what I do (you can have problem in the conversion of the BufferedImage to bytes data) :

package net.bonbonchan.basegame.raster;

import java.awt.Graphics;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;

/**
 *
 * @author Bonbon-Chan
 */
public class Texture
{
    static  protected int lastBind = -1;
    
    private String  name;
    private int width;
    private int height;
        
    private float ratioU;
    private float ratioV;
    
    private boolean hasAlpha;
    private int     handle;
    
    /** Creates a new instance of Texture */
    public Texture()
    {
      ratioU = 1;
      ratioV = 1;
    }

    /**
     * 
     */
    public void destroy()
    {
      if (handle != -1)
      { 
        IntBuffer scratch = BufferUtils.createIntBuffer(1);
        scratch.put(handle);
        scratch.flip();
        GL11.glDeleteTextures( scratch );
        handle = -1;
      }
    }
    
    /**
     * 
     * @param u
     */
    public void setRatioU(float u)
    {
      ratioU = u;
    }
    
    /**
     * 
     * @return
     */
    public float getRatioU()
    {
      return ratioU;
    }
    
    /**
     * 
     * @param v
     */
    public void setRatioV(float v)
    {
      ratioV = v;
    }
    
    /**
     * 
     * @return
     */
    public float getRatioV()
    {
      return ratioV;
    }
    
    /**
     * 
     */
    public void create()
    {
      IntBuffer scratch = BufferUtils.createIntBuffer(1);
      GL11.glGenTextures(scratch);
    
      int error = GL11.glGetError();
      if( error != GL11.GL_NO_ERROR)
      {
        System.out.println("Texture.create : error OpenGL ("+error+")");
      }
      
      handle = scratch.get(0);
    }
    
    /**
     * 
     * @param minFilter
     * @param magFilter
     */
    public void setFilter(int minFilter,int magFilter)
    {
      bind();
      
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, minFilter);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, magFilter);
      
      unbind();
    }
            
    /**
     * 
     * @param width
     * @param height
     * @param type 
     * @param imageData
     */
    public void setImage(int width,int height,int type,ByteBuffer imageData)
    {
      bind();
    
      GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 
                        0, type, GL11.GL_UNSIGNED_BYTE, imageData);
 
      int error = GL11.glGetError();
      if( error != GL11.GL_NO_ERROR)
      {
        System.out.println("Texture.setImage : error OpenGL ("+error+")");
      }
  
      unbind();
    }
    
    /**
     * 
     * @param width
     * @param height
     * @param type 
     * @param imageData
     */
    public void setImage(int width,int height,int type,IntBuffer imageData)
    {
      bind();
    
      GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 
                        0, type, GL11.GL_UNSIGNED_BYTE, imageData);
 
      int error = GL11.glGetError();
      if( error != GL11.GL_NO_ERROR)
      {
        System.out.println("Texture.setImage : error OpenGL ("+error+")");
      }
  
      unbind();
    }
    
    /**
     * 
     * @param img
     */
    public void setImage(BufferedImage img)
    {
      // System.out.println("IMAGE : opaque("+img.getTransparency()+") type("+img.getType()+")");
        
      if(img.getTransparency() == Transparency.OPAQUE)
      {
        if (img.getType() == BufferedImage.TYPE_BYTE_INDEXED)
        {
          BufferedImage img2 = new BufferedImage(img.getWidth(),img.getHeight(),BufferedImage.TYPE_3BYTE_BGR);
          Graphics g = img2.getGraphics();
          g.drawImage(img, 0, 0, null);
          g.dispose();
          setImage(img2);
        }
        else
        {
          ByteBuffer imageData = ByteBuffer.allocateDirect(3 * img.getWidth() * img.getHeight());
          byte data[] = (byte[]) img.getRaster().getDataElements(0, 0, img.getWidth(), img.getHeight(), null);
          imageData.put(data);
          imageData.flip();
        
          setImage(img.getWidth(),img.getHeight(),GL11.GL_RGB,imageData);
        }
      }
      else
      {
        if (img.getType() == BufferedImage.TYPE_INT_ARGB )
        {
          IntBuffer imageData = BufferUtils.createIntBuffer(img.getWidth() * img.getHeight());
          int data[] = (int[]) img.getRaster().getDataElements(0, 0, img.getWidth(), img.getHeight(), null);
          imageData.put(data);
          imageData.flip();
        
          setImage(img.getWidth(),img.getHeight(),GL11.GL_RGBA,imageData);
        }
        else
        {
          ByteBuffer imageData = ByteBuffer.allocateDirect(4 * img.getWidth() * img.getHeight());
          byte data[] = (byte[]) img.getRaster().getDataElements(0, 0, img.getWidth(), img.getHeight(), null);
          imageData.put(data);
          imageData.flip();
        
          setImage(img.getWidth(),img.getHeight(),GL11.GL_RGBA,imageData);
        }
      }
    }
    
    /**
     * 
     * @param warpS
     * @param warpT
     */
    public void setWarp(int warpS,int warpT)
    {
      bind();
        
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, warpS);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, warpT);
      
      unbind();
    }
    
    /**
     * 
     * @return
     */
    public String getName() {
        return name;
    }

    /**
     * 
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 
     * @return
     */
    public int getWidth() {
        return width;
    }

    /**
     * 
     * @param width
     */
    public void setWidth(int width) {
        this.width = width;
    }

    /**
     * 
     * @return
     */
    public int getHeight() {
        return height;
    }

    /**
     * 
     * @param height
     */
    public void setHeight(int height) {
        this.height = height;
    }

    /**
     * 
     * @return
     */
    public boolean isHasAlpha() {
        return hasAlpha;
    }

    /**
     * 
     * @param hasAlpha
     */
    public void setHasAlpha(boolean hasAlpha) {
        this.hasAlpha = hasAlpha;
    }

    /**
     * 
     * @return
     */
    public int getHandle() {
        return handle;
    }

    /**
     * Bind texture (LWJGL)
     */
    public void bind()
    {
      if (lastBind != handle)
      {
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, handle);
        lastBind = handle;
      }
    }
    
    /**
     * 
     */
    public void unbind()
    {
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
      lastBind = -1;
    }
    
}

To use it :


  // Create texture
  Texture texture = new Texture();
  texture.create();

  // Load image
  BufferedImage image = ImageIO.read("...");

  // Set image to the texture
  texture.setImage(image);
  texture.setFilter(GL11.GL_LINEAR,GL11.GL_LINEAR);

  // now you can use the texture
  texture.bind();
  GL11.glBegin(...