Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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  Game Development / Newbie & Debugging Questions / Re: LWJGL Difficulties (Poss Lighting?) on: 2012-01-10 22:46:07
Thank you so much guys Smiley

Its actually runnable... at last lol Tongue

Annoyingly it just shows a white square, but I'll get on it tomorrow when I've got a fresh mind, since I reckon I can fix that.

Thanks, I appreciate it Cheesy

Evan.
2  Game Development / Newbie & Debugging Questions / Re: LWJGL Difficulties (Poss Lighting?) on: 2012-01-10 22:39:07
Turns out I was really stupid and forgot to add control.init() to the main...

But now its got a new problem: "Tue Jan 10 22:33:28 GMT 2012 INFO:Use Java PNG Loader = true
Exception in thread "main" java.lang.NullPointerException"

The error is comming from
1  
texture[0] = TextureLoader.getTexture("png", new FileInputStream("C:\\Documents and Settings\\home user\\My Documents\\My Pictures\\Crate.png"));

And I'm guessing it will then have the same problem with texture[1] and texture[2] aswell. I did change it from bmp to png, but it was the same problem before the change.

I did however define the variable 'tex' as a 'Texture', and changed it so error section of the code is:


1  
2  
3  
4  
tex = TextureLoader.getTexture("png", new FileInputStream("C:\\Documents and Settings\\home user\\My Documents\\My Pictures\\Crate.png"));
texture[0] = TextureLoader.getTexture("png", new FileInputStream("C:\\Documents and Settings\\home user\\My Documents\\My Pictures\\Crate.png"));
texture[1] = TextureLoader.getTexture("png", new FileInputStream("C:\\Documents and Settings\\home user\\My Documents\\My Pictures\\Crate.png"));
texture[2] = TextureLoader.getTexture("png", new FileInputStream("C:\\Documents and Settings\\home user\\My Documents\\My Pictures\\Crate.png"));


The first line isn't comming up with any errors, only the "texture[0]" bit, despite the only thing being different is the variable.

I could come up with a easy fix by turning texture[] into 3 variables, but does anyone know how I can fix it while keeping the array?

Thanks for the help guys Cheesy

Evan
3  Game Development / Newbie & Debugging Questions / LWJGL Difficulties (Poss Lighting?) on: 2012-01-10 22:06:04
Hello,
I am attempting to follow the NeHe tutorials, but am converting it to LWJGL as its what I am most familiar with. However I have encountered a problem in lesson 7, which I cannot get past no matter what.

Below is the relevant code in which I think the solution will be in (I'll ignore putting everything else here, seeing as its so much...):

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  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
private static float[] LightAmbient = {0.5f, 0.5f, 0.5f, 1.0f}; // Red Green Blue Alpha
private static float[] LightDiffuse = {1.0f, 1.0f, 1.0f, 1.0f };
private static float[] LightPosition = { 0.0f, 0.0f, 2.0f, 1.0f };
   
int filter = 0;
private Texture texture[];
private Texture tex;
   
   
   
private static boolean initGL() {
   ByteBuffer temp = ByteBuffer.allocateDirect(16);
   temp.order(ByteOrder.nativeOrder());
   GL11.glMatrixMode(GL11.GL_PROJECTION);
   GL11.glLoadIdentity();
   
   GLU.gluPerspective(45.0f, 800/600,0.1f,100f);
   GL11.glMatrixMode(GL11.GL_MODELVIEW);
   GL11.glLoadIdentity();
   
   GL11.glShadeModel(GL11.GL_SMOOTH);
   GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   GL11.glClearDepth(1.0f);
   GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer)temp.asFloatBuffer().put(LightAmbient).flip());
   GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(LightDiffuse).flip());
   GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, (FloatBuffer)temp.asFloatBuffer().put(LightPosition).flip());
   GL11.glEnable(GL11.GL_LIGHT1);
   GL11.glEnable(GL11.GL_LIGHTING);
   GL11.glEnable(GL11.GL_DEPTH_TEST);
   GL11.glDepthFunc(GL11.GL_LEQUAL);
   GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
   return true;

}

public void init() {
      try {
         tex = TextureLoader.getTexture("png", new FileInputStream("C:\\Documents and Settings\\home user\\My Documents\\My Pictures\\Crate.png"));
texture[0] = TextureLoader.getTexture("png", new FileInputStream("C:\\Documents and Settings\\home user\\My Documents\\My Pictures\\Crate.png"));
texture[1] = TextureLoader.getTexture("png", new FileInputStream("C:\\Documents and Settings\\home user\\My Documents\\My Pictures\\Crate.png"));
texture[2] = TextureLoader.getTexture("png", new FileInputStream("C:\\Documents and Settings\\home user\\My Documents\\My Pictures\\Crate.png"));

      } catch (IOException e) {
            System.err.println("No picy!");
            e.printStackTrace();
         }
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture[0].getTextureID());
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
     
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture[1].getTextureID());
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
     
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture[2].getTextureID());
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_NEAREST);
      //GL11.glTexImage2D(0,3,texture.getImageWidth(),texture.getImageHeight(),0,GL11.GL_RGB,GL11.GL_UNSIGNED_BYTE,texture.GL11.getTexture());
  }
   
   private void render(){
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
      GL11.glLoadIdentity();
     
      GL11.glTranslatef(0.0f, 0.0f, z);
      GL11.glRotatef(xrot,1.0f,0.0f,0.0f);
      GL11.glRotatef(yrot,0.0f,1.0f,0.0f);
      if (filter == 0) {
         
      }
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture[filter].getTextureID()); // <-- Here, this line is where the error is appearing
     GL11.glBegin(GL11.GL_QUADS);
      //front
     GL11.glNormal3f(0.0f, 0.0f, 1.0f);
      GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex3f(-1.0f, -1.0f, 1.0f);
      GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex3f(1.0f, -1.0f, 1.0f);
      GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex3f(1.0f, 1.0f, 1.0f);
      GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3f(-1.0f, 1.0f, 1.0f);
               //The rest of the code is fine, so I left it out :)


The error that eclipse gives me is "Tue Jan 10 22:33:28 GMT 2012 INFO:Use Java PNG Loader = true
Exception in thread "main" java.lang.NullPointerException" and it is at the
texture[0] = TextureLoader.getTexture("png", new FileInputStream("C:\\Documents and Settings\\home user\\My Documents\\My Pictures\\Crate.png"));
line in init(). I have tried loads of different methods to doing this, and all have came up with different errors, and this is the last error I have which I cant fix.

The reason I have added the 'tex = TextureLoader...' above the 'texture[0] line is simply to check the last section of the error line is correct, and it is, as the tex line isn't throwing up any errors.

Also, is anyone able to give me a hand in avoiding using the floatBuffers in InitGL so instead of:
1  
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer)temp.asFloatBuffer().put(LightAmbient).flip());


it is
1  
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, LightAmbient);


The floatbuffer I found after a few google searches, but Im struggling to get my head around float buffer, so was wondering if there is anyway around this?

Thanks,
Evan.



EDIT: I change the code a little to a revised one since I posted this, so the question also changed, just to clear up any confusion.
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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (46 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (64 views)
2014-09-21 02:42:18

BurntPizza (36 views)
2014-09-21 01:30:30

moogie (42 views)
2014-09-21 00:26:15

UprightPath (51 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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!