Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (483)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / JOGL Development / Re: Texture Mapping on: 2004-03-21 07:57:48
Okay sorry to be a pain in the a$$, but this still ain;t working for me!

I have taken your advice and made the glBind calls outside the  Begin and End statements... but this still only seems to draw the last texture that I intialised. Can you help? I will post most of the program here, it is just jogl nehe lesson 6 with a few extra textures added.

There are a few methods within this that i don't understand fully, so maybe the problem lies in there somewhere.

This is my display method...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
      gl.glBindTexture(GL.GL_TEXTURE_2D, texture1);
      gl.glBegin(GL.GL_QUADS);
        // Front Face
       gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f,  1.0f);
        gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f,  1.0f);
        gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f,  1.0f);
        gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f,  1.0f);
      gl.glEnd();
     
     
      gl.glBindTexture(GL.GL_TEXTURE_2D, texture2);
      gl.glBegin(GL.GL_QUADS);
        // Back Face
       gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f);
        gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f, -1.0f);
        gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f, -1.0f);
        gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f, -1.0f);
      gl.glEnd();


      gl.glBindTexture(GL.GL_TEXTURE_2D, texture3);
      gl.glBegin(GL.GL_QUADS);
        // Right face
       gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f, -1.0f);
        gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f, -1.0f);
        gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f,  1.0f);
        gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f,  1.0f);
      gl.glEnd();
     
      gl.glBindTexture(GL.GL_TEXTURE_2D, texture4);
      gl.glBegin(GL.GL_QUADS);
        // Left Face
       gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f);
        gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f,  1.0f);
        gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f,  1.0f);
        gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f, -1.0f);
      gl.glEnd();



And this is my init() method...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
final GL gl = gLDrawable.getGL();
      gl.glShadeModel(GL.GL_SMOOTH);              // Enable Smooth Shading
     gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);    // Black Background
     gl.glClearDepth(1.0f);                      // Depth Buffer Setup
     gl.glEnable(GL.GL_DEPTH_TEST);                                          // Enables Depth Testing
     gl.glDepthFunc(GL.GL_LEQUAL);                                                // The Type Of Depth Testing To Do
     gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);      // Really Nice Perspective Calculations
     gl.glEnable(GL.GL_TEXTURE_2D);
      gLDrawable.addKeyListener(this);
     
      texture1 = genTexture(gl);
      gl.glBindTexture(GL.GL_TEXTURE_2D, texture1);
      BufferedImage img1 = readPNGImage("data/NeHe.png");
      makeRGBTexture(gl, gLDrawable.getGLU(), img1, GL.GL_TEXTURE_2D, false);
     
      texture2 = genTexture(gl);
      gl.glBindTexture(GL.GL_TEXTURE_2D, texture2);
      BufferedImage img2 = readPNGImage("data/HL_Pitch_Big.png");
      makeRGBTexture(gl, gLDrawable.getGLU(), img2, GL.GL_TEXTURE_2D, false);
     
      texture3 = genTexture(gl);
      gl.glBindTexture(GL.GL_TEXTURE_2D, texture3);
      BufferedImage img3 = readPNGImage("data/NeHe.png");
      makeRGBTexture(gl, gLDrawable.getGLU(), img3, GL.GL_TEXTURE_2D, false);
     
      texture4 = genTexture(gl);
      gl.glBindTexture(GL.GL_TEXTURE_2D, texture4);
      BufferedImage img4 = readPNGImage("data/Shading_Velocity_Big.png");
      makeRGBTexture(gl, gLDrawable.getGLU(), img4, GL.GL_TEXTURE_2D, false);
     
              gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MIN_FILTER,GL.GL_LINEAR);
              gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MAG_FILTER,GL.GL_LINEAR);




And finally, these are the methods that I don't fully understand... I have a feeling that the problem lies maybe in the last method, private int genTexture(GL gl).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
    private BufferedImage readPNGImage(String resourceName)
    {
      try
      {
        URL url = getResource(resourceName);
        if (url == null)
        {
          throw new RuntimeException("Error reading resource " + resourceName);
        }
        BufferedImage img = ImageIO.read(url);
        java.awt.geom.AffineTransform tx = java.awt.geom.AffineTransform.getScaleInstance(1, -1);
        tx.translate(0, -img.getHeight(null));
        AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
        img = op.filter(img, null);
        return img;
      }
      catch (IOException e)
      {
        throw new RuntimeException(e);
      }
    }
   
    private void makeRGBTexture(GL gl, GLU glu, BufferedImage img, int target, boolean mipmapped)
    {
      ByteBuffer dest = null;
      switch (img.getType())
      {
        case BufferedImage.TYPE_3BYTE_BGR:
        case BufferedImage.TYPE_CUSTOM:
        {
          byte[] data = ((DataBufferByte) img.getRaster().getDataBuffer()).getData();
          dest = ByteBuffer.allocateDirect(data.length);
          dest.order(ByteOrder.nativeOrder());
          dest.put(data, 0, data.length);
          break;
        }
        case BufferedImage.TYPE_INT_RGB:
        {
          int[] data = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
          dest = ByteBuffer.allocateDirect(data.length * BufferUtils.SIZEOF_INT);
          dest.order(ByteOrder.nativeOrder());
          dest.asIntBuffer().put(data, 0, data.length);
          break;
        }
        default:
          throw new RuntimeException("Unsupported image type " + img.getType());
      }
     
      if (mipmapped)
      {
        glu.gluBuild2DMipmaps(target, GL.GL_RGB8, img.getWidth(), img.getHeight(), GL.GL_RGB, GL.GL_UNSIGNED_BYTE, dest);
      }
      else
      {
        gl.glTexImage2D(target, 0, GL.GL_RGB, img.getWidth(), img.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, dest);
      }
    }

    private int genTexture(GL gl)
    {
      final int[] tmp = new int[1];
      gl.glGenTextures(1, tmp);
      return tmp[0];
    }



Thanks again for any help provided.
2  Java Game APIs & Engines / JOGL Development / Re: Texture Mapping on: 2004-03-20 09:45:33
I have tried this but it doesn't seem to work... it only displays the last texture that was initialised on all the cube sides.

I want to display four different textures on the same cube, so that I have one texture on the front of the cube, another texture on the back of the cube, one texture on the left side of the cube, and finally one texture on the right side of the cube. the top and bottom are not required as I will only be rotating the cube along the y axis...

this is what i have so far...

//draw the cube within the display() method

gl.glBegin(GL.GL_QUADS);

// Front Face
gl.glBindTexture(GL.GL_TEXTURE_2D, texture1);
gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f,  1.0f);
gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f,  1.0f);
gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f,  1.0f);
gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f,  1.0f);

// Back Face        
gl.glBindTexture(GL.GL_TEXTURE_2D, texture2);
gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f);
gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f, -1.0f);
gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f, -1.0f);
gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f, -1.0f);

// Right face    
gl.glBindTexture(GL.GL_TEXTURE_2D, texture3);
gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f, -1.0f);
gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f, -1.0f);
gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f,  1.0f);
gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f,  1.0f);
       
// Left Face
gl.glBindTexture(GL.GL_TEXTURE_2D, texture4);
gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f);
gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f,  1.0f);
gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f,  1.0f);
gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f, -1.0f);

gl.glEnd();




then this is my init() method, it is basically straight out of NeHE Lesson 06 about Texture Mapping, I have just created three extra textures.


public void init(GLDrawable gLDrawable)
   {

final GL gl = gLDrawable.getGL();
gl.glShadeModel(GL.GL_SMOOTH);gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
gl.glClearDepth(1.0f);gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);Calculations
gl.glEnable(GL.GL_TEXTURE_2D);
gLDrawable.addKeyListener(this);
     
texture1 = genTexture(gl);
gl.glBindTexture(GL.GL_TEXTURE_2D, texture1);
BufferedImage img1 = readPNGImage("data/NeHe.png");
makeRGBTexture(gl, gLDrawable.getGLU(), img1, GL.GL_TEXTURE_2D, false);
     
texture2 = genTexture(gl);
gl.glBindTexture(GL.GL_TEXTURE_2D, texture2);
BufferedImage img2 = readPNGImage("data/HL_Pitch_Big.png");
makeRGBTexture(gl, gLDrawable.getGLU(), img2, GL.GL_TEXTURE_2D, false);
     
texture3 = genTexture(gl);
gl.glBindTexture(GL.GL_TEXTURE_2D, texture3);
BufferedImage img3 = readPNGImage("data/NeHe.png");
makeRGBTexture(gl, gLDrawable.getGLU(), img3, GL.GL_TEXTURE_2D, false);
     
texture4 = genTexture(gl);
gl.glBindTexture(GL.GL_TEXTURE_2D, texture4);
BufferedImage img4 = readPNGImage("data/Shading_Velocity_Big.png");
makeRGBTexture(gl, gLDrawable.getGLU(), img4, GL.GL_TEXTURE_2D, false);
     
gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MIN_FILTER,GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MAG_FILTER,GL.GL_LINEAR);
}


Any help would be great!
Thanks
3  Java Game APIs & Engines / JOGL Development / Texture Mapping on: 2004-03-20 05:35:15
Hi,

I've looked at the example of texture mapping on the NeHe site, and was wondering if you can put four different images on the four sides of the cube??

Thanks!
4  Java Game APIs & Engines / JOGL Development / color on: 2004-03-13 14:11:30
Im am drawing 3d shapes and and wanting to set different sides to different colors to represent different things.

When I draw a 3d triangle, I do it by drawing the four faces, (front, back, right, and left). Each side then has the three vertices, each with its own color.... (gl.glColor(1.0f, 0.0f, 0.0f).

Say I want to set the front side of the triangle to black and then the back side to be red. When I try to implement this because the top point of my triangle is used by all sides as there top point there is shading running through into all sides of my triangle. How can I make each side disticnt from the other, so that there is no color merging?

Thanks.
5  Java Game APIs & Engines / JOGL Development / glTranslate on: 2004-03-13 13:02:26
Hi,

I am drawing a series of triangles using a for loop. These triangles are drawn using various values within arrays.

I can output the correct amount of triangles all at the correct size according to the array values. However I am wanting to output them in a line effect, one after the other.

So within my display method, I have a for loop, then I have something like this...

gl.glTriangles;
//for statement goes here...

//draw triangles here
//finish triangles here

gl.glTranslate(translateVariable, 0.0f, 0.0f);
translateVariable++;

//end for loop


So, I thought that this would then draw one triangle, then translate along the x axis a bit, draw another triangle, move along the x axis again... and so on. Until the for loop ends.

The triangles are all draw, but on top of one another, how can I make them draw one, then move along the x axis a little, draw the next, then again move along the x axis, etc.

Any help would be great! I'm thinking that its a simple error that I'm making!

Thanks
6  Java Game APIs & Engines / JOGL Development / Rotation on: 2004-03-08 11:40:42
Hi,

Im using key presses to ratate a shape on the canvas. At the minute I have the rotate set as a small incremental when a button is pressed.

However, I want to be able to change this so that instead of the user having to hold down the button to rotate the shape 90 degrees, i want to them to be able to push the button once, and it will automatically rotate the 90 degrees.

I have set the small incremental that i already had into a for loop, so that when the button was pressed the shape would rotate the total 90 degrees with one key press. I was however hoping for the gradual effect of a rotation, like in the nehe examples when the shapes are constantly rotated. Instead it simply snapped round straight away the 90 degrees.

Does anyone know a way of getting the effect that I am after?

Thanks.
7  Java Game APIs & Engines / JOGL Development / GLCanvas on: 2004-03-08 11:07:30
Hi,

Im trying to scroll along the GLCanvas... is there any way that this can be done?

Im using an array to draw out a series of shapes, but the get cut off once they reach the end of the canvas. Is there a method you can use, so that you can move along the canvas to see the rest of the shapes displayed by my array??

I was trying to use the glRotate method... but I coulldn't get it to do what i wanted.

Thanks.
8  Java Game APIs & Engines / JOGL Development / Drawing Shapes on: 2004-03-02 16:55:45
Hi,

Is there a quick and easy way to draw shapes?
Like, drawTriangle(10, 10, 10), where the values in the brackets are values representing the length, breadth, and width?

What im trying to do is, I have three array with values. I want to represent these visually. Preferably with 3D shapes.

Whats the best way to implement them into a shape to that the first array determines the position on the y axis, the second array values determine the length of the shape on the x axis, and the third array values determine the length of the shapes on the z axis??

Its all getting very confusing for me?!

Thanks!
9  Java Game APIs & Engines / JOGL Development / Re: scrolling properties on: 2004-03-02 05:43:42
I took a look at the demo and its a good effect, but it doesn't help me as much as I thought...

I want to 'look down the array' (like looking into a mirror with a mirror behind it)... so that I could see all the shapes that have been cut off due to the size of my canvas.

I have seen before how you can zoom in and out, but is there a code example where you can rotate the camera on its x axis and y axis using key presses??
10  Java Game APIs & Engines / JOGL Development / Re: scrolling properties on: 2004-03-01 13:53:46
where is that demo??     Huh
11  Java Game APIs & Engines / JOGL Development / Re: scrolling properties on: 2004-03-01 12:17:24
I was thinking about the camera angle option...

Can you give me some sample code on how you could change the camera angle, by two ways...

first zooming in and out, and secondly by tilting along x axis. It would be best if I could allow the application be viewed to the users descretion, i.e. allowing buttons to do the zooming and tilting.

Thanks!
12  Java Game APIs & Engines / JOGL Development / Re: scrolling properties on: 2004-03-01 06:37:33
Even if the opengl canvas is put on top of a JFrame... can I still not make that scrollable to get round my problem??
13  Java Game APIs & Engines / JOGL Development / scrolling properties on: 2004-02-29 11:12:46
How do I put a scroll bar onto a jogl canvas??

I am reading values from an array to draw a series of triangle. The canvas will only show the first triangles that are drawn from the values from the array.

How can I set a scroll bar or a scrolling property so that the I can show all the triangles drawn from the array??

Thanks!
14  Java Game APIs & Engines / JOGL Development / public void display class on: 2004-02-27 15:38:39
Hi,

I am trying to use an array of variables to draw a series of 2d/3d shapes on a canvas...

When I use a for statement to loop through the array, its loops through the array endlessly. Is there any way to stop this, so that it will only loop through the array once??

here is a code snippet.

public void display(GLDrawable gLDrawable) {

for (int k=0; k<array.length; k++) {

final GL gl = gLDrawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();

gl.glTranslate(-1.5f, 0.0f, -6.0f);
gl.glBegin(GL.GL_TRIANGLES);

//code to draw a 2d triangle...

gl.glEnd();
gl.glTranslate(3.0f, 0.0f, 0.0f);

}

}

-----------------------------------------------

I have a test array of length = 2. So in theory this should draw two trianlges (one over the top of each other), but i get a constant loop where there is a bigger triangle on the left of the canvas and a smaller triangle to the right....

could anyone shed some light onto why this is looping through my array endlessly??

Many Thanks,
lillyhammer
15  Java Game APIs & Engines / JOGL Development / ASCII Key Values on: 2004-02-13 11:49:44
Within the KeyPressed method in a simple JOGL program, could anyone be so kind to tell me what the value would be if the KeyEvent were to be 'L'??

Thanks!
16  Java Game APIs & Engines / JOGL Development / Newbie: Initializing and drawing 3D Objects on: 2004-02-02 12:40:30
Hi,

I'm new to this and got some help from a previous thread, but I still can't seem to find an example of where I can display three-dimensional objects, for instance, cubes, spheres, etc...

I have read from different sources and have no problems with ordinary 2d polygons, but I can't get my head round how to display a 3d object.

Any examples I find aren't designed for jogl, but for C/C++. I don't have any experience in C/C++, so its proving to be difficult for me!

Any help would be great, a simple example would be even better!!  Grin

Thanks,
lillyhammer
17  Java Game APIs & Engines / JOGL Development / Re: Reading in binary to display 3d shapes on: 2004-02-01 10:04:57
Sorry, I should have been more specific the first time...

What I am trying to do is read in from a MIDI file, this is mostly binary numbers. Then take this data and use it to form a representation of the data.

Therefore I need two things...

First a basic demo on how to create 3d shapes and secondly if there is a generic code fragment that allows you to read from a file, such as this MIDI file.

Thanks in advance!
18  Java Game APIs & Engines / JOGL Development / Reading in binary to display 3d shapes on: 2004-01-31 07:45:32
Hi,

I'm new to this and would appreciate any help to get started using JOGL. I'm finding it a tad difficult at times!

I am wanting to read data from an external source and then use that data to plot it and draw 3d shapes. So the main problem is finding out how to read this data in from an exeternal file. The data will be in binary.

Any tips or solutions would be greatly appreciated, thanks!
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (14 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!