Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (578)
games submitted by our members
Games in WIP (499)
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: Problem with getting LWJGL to work outside of Eclipse on: 2014-04-17 15:39:13
@trollwarrior1
I'll say what the guy who made that other comment said: "You are a saint! Thank you so much!"!!
Just one new line of coad, calling that function, and all of a sudden it works (as long as you have that "nat" folder of course =)
2  Game Development / Newbie & Debugging Questions / Re: Problem with getting LWJGL to work outside of Eclipse on: 2014-04-17 13:15:11
@trollwarrior1
I did as you told me to and I did indeed get an error message. However I don't quite understand what it means. Could you help me?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
C:\Users\Admin>java -jar TestOpenGL.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Mathod)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
   at java.lang.ClassLoader.loadLibrary(Unknown Source)
   at java.lang.Runtime.loadLibrary0(Unknown Source)
   at java.lang.System.loadLibrary(Unknown Source)
   at org.lwjgl.Sys$1.run(Sys.java:73)
   at java.security.AccessController.doPrivileged(Native Method)
   at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
   at org.lwjgl.Sys.loadLibrary(Sys.java:95)
   at org.lwjgl.Sys.<clinit>(Sys.java:112)
   at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
   at OpenGL_Example.main(OpenGL_Example.java:26)
   ... 5 more
3  Game Development / Newbie & Debugging Questions / Problem with getting LWJGL to work outside of Eclipse on: 2014-04-17 11:35:25
I have the problem that when I work in Eclipse I can get a window to open as it should but for some reason I can't get it to start once I've exported the program to a JAR-file. I made a very simple example where I only draw a single image on the center of the screen and tried that. It worked in Eclipse and it didn't work once exported (in a way I'm glad that is so, it shows the problem is quite basic and not a huge error in my other program).
I've added in the code here so that you can see. It works in Eclipse, but not when exported.

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  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.ARBDebugOutput.*;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;

import javax.imageio.ImageIO;
import javax.swing.JOptionPane;

import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.ARBDebugOutputCallback;
import org.lwjgl.opengl.ContextAttribs;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.opengl.PixelFormat;


public class OpenGL_Example {

   public static void main(String[] args) {
      try {
         //Display.setDisplayMode(new DisplayMode(600, 400));
        Display.setDisplayModeAndFullscreen(Display.getDesktopDisplayMode());
         Display.create(new PixelFormat(), new ContextAttribs().withDebug(true));
         //Display.setVSyncEnabled(true);
        if(GLContext.getCapabilities().GL_ARB_debug_output){
            glDebugMessageCallbackARB(new ARBDebugOutputCallback());
         }
      } catch (LWJGLException e) {
         e.printStackTrace();
      }
     
      BufferedImage image = null;
     
      try {
         image = ImageIO.read(new File("BucketKitties.jpg"));   //Just your average cat image
     } catch (IOException e) {
         e.printStackTrace();
      }
     
      int width = image.getWidth(), height = image.getHeight();
      int[] pixels = image.getRGB(0, 0, width, height, new int[width*height], 0, width);
     
      ByteBuffer data = BufferUtils.createByteBuffer(3*width*height);
      //System.out.println(data);
     for(int i = 0; i < pixels.length; i++){
         int pixel = pixels[i];
         data.put((byte) ((pixel >> 16) & 0xFF));     // Red component
           data.put((byte) ((pixel >> 8) & 0xFF));      // Green component
           data.put((byte) (pixel & 0xFF));          // Blue component
     }
      //System.out.println(data);
     data.flip();      //Sets the Reading Marker to the start of the buffer
     //System.out.println(data);
     
      int texture = glGenTextures();
      glBindTexture(GL_TEXTURE_2D, texture);
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
     
      //We don't need different sized images for this
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     
      glEnable(GL_TEXTURE_2D);
     
     
      while(!Display.isCloseRequested()){
         
         glClearColor(0, 0, 0, 0);
          glClear(GL_COLOR_BUFFER_BIT);
         
          glMatrixMode(GL_PROJECTION);   //Loads the Projection-matrix
         glLoadIdentity();   //Resets the projection-matrix
         //Sets a coordinate system where one pixel on the screen equals one coordinate
         glOrtho(0, Display.getWidth(), Display.getHeight(), 0, -1, 1);  
         
          glMatrixMode(GL_MODELVIEW);   //The "Camera Position Matrix"
         glLoadIdentity();  
          glTranslatef(Display.getWidth()/2, Display.getHeight()/2, 0);   //We want to draw with the center of the screen as (0, 0)
         
          glBegin(GL_QUADS);
          {
             glColor3f(1, 1, 1);
             glTexCoord2f(0, 0);
             glVertex2f(-250, -250);
             
             //glColor3f(0, 1, 0);
            glTexCoord2f(1, 0);
             glVertex2f(250, -250);
             
             //glColor3f(0.5f, 0.5f, 0.5f);
            glTexCoord2f(1, 1);
             glVertex2f(250, 250);
             
             //glColor3f(0, 0, 1);
            glTexCoord2f(0, 1);
             glVertex2f(-250, 250);
          }
          glEnd();
         
         Display.sync(100);
         Display.update();
      }
      Display.destroy();
      JOptionPane.showMessageDialog(null, "Complete!");
   }

}
4  Game Development / Newbie & Debugging Questions / Re: Export from Eclipse causes trouble on: 2014-04-17 10:46:28
@trollwarrior1
I'm terribly sorry but I'm afraid I don't under stand what you mean. I don't know if I load any files with .internal (I don't even know what that is).
At least I have now been able to determine that the file is loaded as it should be and that the problem comes when I try to run the program.
5  Game Development / Newbie & Debugging Questions / Re: Export from Eclipse causes trouble on: 2014-04-17 10:32:48
I'm afraid it's hard for me to check where it goes wrong. I have notifications right before and after I load the serialization-file and as I said they pop up perfectly when running in Eclipse but only the one before seems to pop up when I run it after exporting it
6  Game Development / Newbie & Debugging Questions / Export from Eclipse causes trouble on: 2014-04-16 13:45:24
I'm using LWJGL to make a game.
Now I have a demo version that works perfectly but when I try to export it into a runnable jar file that file doesn't work.
I am using Serializable to store the state I need it to start in, which as I said works perfectly when started in Eclipse.
One thing that I noticed is that when I try to export it I get a warning message I have never seen before, maybe that is the reason? The message says as follows:
----------------------------------------------------------------------------
This operation repacks referenced libraries.
Please review the licenses associated with libraries you wish to reference to
make sure you are able to repack them using this application. Note also that
this operation does not copy signature files from original libraries to the
generated JAR file.
----------------------------------------------------------------------------
This error message did not appear if I changed the export setting from "Extract required libraries into the generated JAR" to "Package required libraries into generated JAR" but it made no difference. The program still didn't work.
At least it seems like it didn't crash, using the Task Manager it's possible to see that the java virtual machine is running until you stop it and it doesn't say that it's not answering so it shouldn't be completely crashed down.

Anyone has some ideas?
7  Game Development / Newbie & Debugging Questions / Identifying Subclasses on: 2014-04-15 12:30:08
I am making a simple 2D platform game and I have run into a slight problem with the Spells I want the player and NPCs to use.
I have an abstract class Spell and a set of subclasses extending Spell. These subclasses indicate the element of the spell, so one subclass might be Fire_Spell. I want to be able to receive a Spell and do something like
1  
2  
3  
if(spell.getClass() == Fire_Spell){
     doStuff();
}

But I can't figure out how to identify if spell is a certain subclass since whenever I try to compare the instance of Spell I have (which will never really be a Spell, always one of the subclasses of Spell) I just can't find a way that doesn't either end in an error or which gives a faulty answer.

I have tried something like "attack.isAssignableFrom(Fire_Spell)" and "attack.getClass().isAssignableFrom(Fire_Spell)" but those just say that "Fire_Spellcannot be resolved to a variable" so I wonder what I'm doing wrong.
8  Game Development / Newbie & Debugging Questions / Re: Listening to Keyboard while using OpenGL on: 2014-04-10 08:33:54
Thank you Agent.
Now it works perfectly and as a bonus I can even use it the same way as that GameCore you helped me write (with a boolean[])
9  Game Development / Newbie & Debugging Questions / Re: Listening to Keyboard while using OpenGL on: 2014-04-09 23:33:05
Hello again!

I got it working and all that now but there is one problem I have.
The Keyboard doesn't seem to generate any Events when you press the arrow-keys. It works for all letters and such but not for the arrows.
Since I'm making a game this is a bit inconvenient. Does anyone have a solution?
I'd be happy enough if I could make the arrow-keys cause an Event pointing at the W, S, A, D keys since they are often used too for movement.

One more thing, I get which key caused the Event by calling getEventCharacter() and it works fine for pressing keys but I just get a blank instead of a key when I release the key. I need a reliable way of telling when a certain key which is held down is released. Any ideas?
10  Game Development / Newbie & Debugging Questions / Re: Problem with Writing text to a File on: 2014-04-09 13:43:03
Thank you for the help everyone!
I managed to solve the problem by simply reading/writing the encrypted text as pure short values.
11  Game Development / Newbie & Debugging Questions / Re: Listening to Keyboard while using OpenGL on: 2014-04-09 13:34:40
@tom_mai78101
Thank you for a lot of information. I'm going to start reading it straight away  Grin
One quick questiong though (to avoid doing an embarrasing mistake like I did recently), does the KyeBoard have to be controlled by the same Thread as the one which handles OpenGL or can I just create it and let another Thread handle it? I want to have one Thread for the graphics and one for everything else and if it's possible to do this it would simplify things.

Thank you very much for the help!
12  Game Development / Newbie & Debugging Questions / Listening to Keyboard while using OpenGL on: 2014-04-09 09:24:35
I have just started using OpenGL and I need to be able to listen to the keyboard.
Earlier I used to make a boolean[] (of length 8192) and add a KeyListener. Then I'd just set it so that the information would get put into the array. Like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
buttonsPressed = new boolean[8192];
      frame.addKeyListener(new KeyListener() {
         
         @Override
         public void keyTyped(KeyEvent e) {/*Not used*/}
         
         @Override
         public void keyPressed(KeyEvent e) {
            buttonsPressed[e.getKeyCode()] = true;
         }
         
         @Override
         public void keyReleased(KeyEvent e) {
            buttonsPressed[e.getKeyCode()] = false;
         }
      });


Now I wonder, how am I supposed to do the same thing with OpenGL?
I have no idea how to do this, can you just go "Display.addaddKeyListener(new KeyListener()..." maybe? (I find that a bit unlikely)
13  Game Development / Newbie & Debugging Questions / Re: Problem with Writing text to a File on: 2014-03-31 21:03:54
How do you make it appear with "code tags"? I really is easier to read that way XD


Well, earlier I worked my encryption on chars but I tried making it so that I worked with bytes from the time I read the data from a file until I wrote it to a new file after having first encrypted and then decrypted it. Well, it still didn't work but I think the problem is when I write to the file mainly. If I convert a byte into a char then it sometimes makes me lose data. I'm really at a loss here.
If anyone has some completely failsafe code for taking a String, writing it to a file, and then reading it from that file without losing ANY information no matter what chars are in the String (as long as they have a numberical value between 1 and 255 it should always work) then I would really love to get a copy of that code
14  Game Development / Newbie & Debugging Questions / Problem with Writing text to a File on: 2014-03-31 00:48:15
I have a problem when I want to write text to a file. This isn't really "normal" text as it has been run through a RSA-crypto but no matter what I do I can't seem to save the data in the same way that I have it in my Java program so when I read it from the file and run it through the decryption it becomes wierd. And just to make sure, as long as I don't write and read the data to a file the decryption works perfectly so it's not that which is a problem.

The lines I encrypt: Ok
                           we are testing if this works
                           and I hope the different rows come in

What the encrypted data looks like if you use println on it: 5Ù4ÔU+?Y_+?3+:3O? ?OÉ?3?O:?UP_Ù:4ÔY?í?Õ??P,+?3?+?íOÉÉ+_+?3?_PU:?âPV+?O?

What it looks like after writing, reading and decryption: Ok
                                                                          we¼are¼testi¼g¼if¼t¼is¼works
                                                                          a¼d¼I¼¼ope¼t¼e¼differe¼t¼rows¼come¼i¼

My writing function:
   public static void writeFile(String path, String text) throws IOException{ 
       OutputStream out = null;
       try{ 
           out = new FileOutputStream(path); 
           byte[] totalBytes = text.getBytes(); 
           out.write(totalBytes); 
            } 
          finally{ 
          if(out !=null) 
              out.close(); 
            } 
        }


My reading function:
   public static String readFile(String path) throws IOException{ 
       String sContent=null; 
       byte [] buffer =null; 
       File a_file = new File(path); 
       try 
       { 
       FileInputStream fis = new FileInputStream(path); 
       int length = (int)a_file.length(); 
       buffer = new byte [length]; 
       fis.read(buffer); 
       fis.close(); 
       } 
       catch(IOException e){e.printStackTrace();}
      
       sContent = new String(buffer); 
       return sContent; 
       } 
15  Game Development / Networking & Multiplayer / Re: How do you configure a router with Java to make it... on: 2014-03-30 23:03:39
@opiop65
No, I'm afraid I don't know very much at all. The only knowledge I have about it is what I got from a single course in my university program and it dealt with networks as a whole so it didn't go too deep into routers in particular. Still, at least it made me know why it never worked if I tried to host a minecraft server  XD
16  Game Development / Networking & Multiplayer / Re: How do you configure a router with Java to make it... on: 2014-03-30 19:23:11
@Pauler
Well, it is my hope to be able to publish the game so that anyone can download it and host a server so it'd be really good if I could include some code in the server to open a port in the router automatically when the server starts up. After all, it's good if your game can be used easily by anyone, even those who aren't good at computers.

@saucymeatman
That library really looks good when it comes to sending and receiving stuff. I wonder if it solves my problem though. I couldn't quite make out if it allows you to bypass the problem with the router not knowing which incoming messages that are supposed to be sent to the server on my computer. Do you know if it has an option for "port forwarding" on the router (or what else it might be called, I want my program to be able to tell the router that any incoming message with destination port 6677 (for example) are to be sent to my computer).
17  Game Development / Networking & Multiplayer / How do you configure a router with Java to make it... on: 2014-03-29 18:21:48
I have started working with making a game meant to be played by several persons across the web.
I have it working and all, you can open it and play in a LAN but I have a problem. When I want to connect to another computer through the internet, not a LAN, the NAT in the router gets in the way (of course, it doesn't know that an incomming call is for my computer and not my brother's).
So, I know there are ways to configure a router, from your computer, so that it sends all calls to a certain Port to the same computer in the house. What I'm wondering is if there is a way to do this with Java and in that case I'd love to see some code with a function that takes an Integer (a port number) and makes the router send all received messages with that destination port to the computer that used this function. That way I'll be able to set up a connection and let the game clients communicate with each other.

I hope this wasn't confusing, I don't know how to write it better I'm afraid.
18  Game Development / Newbie & Debugging Questions / Problem with Saving information in a .txt file on: 2013-10-03 13:58:22
Hello!

I'm using a PrintWriter to write a String into a file. So far so good. However, now I'm trying to make an encryption program and I noticed that some numbers just don't go well.
For example: if a char after encryption has the integer value of 157 then if I write a String containing that char to a .txt file and then read it in again then it will have changed to 63...
Same things happen for several values such as 137 for example (which also becomes 63). Why is this happening and how can I avoid it?
It's making my decryption give me faulty results in the case of those characters however the problem only appears when I save to a file and load it again before decrypting it. The decryption works perfectly if I use it on the String without first writing it to a file.
19  Game Development / Newbie & Debugging Questions / Going through a set number of methods in a random order without repeating any on: 2013-09-05 23:56:47
Hello!

I'm trying to make a program that generates a random labyrinth, I do this by using a Randomized Depth-First (se wikipedia, http://en.wikipedia.org/wiki/Maze_generation_algorithm , for the basic idea). I have just one problem, I want to be going in randomized directions but I don't want the program to check the same direction twice. So I want it to pick a random direction and if that "cell" has already been visited (meaning there can't be a path going from the current cell to that cell) then I want the program to check another direction from the current cell without ever checking the same direction again (since we know it's unavailable).
One suggestion I was considering is to create a collection and mixing it with Collection.shuffle but I've never used collections before and I don't know how to use that to make the program call 4 methods in a random order that way.
Anyone have a recommendation or a good trick I can use?

Thank you!
20  Game Development / Game Mechanics / Effectively chosing a random direction on: 2013-09-05 23:53:41
Hello!

I'm trying to make a program that generates a random labyrinth, I do this by using a Randomized Depth-First (se wikipedia, http://en.wikipedia.org/wiki/Maze_generation_algorithm , for the basic idea). I have just one problem, I want to be going in randomized directions but I don't want the program to check the same direction twice. So I want it to pick a random direction and if that "cell" has already been visited (meaning there can't be a path going from the current cell to that cell) then I want the program to check another direction from the current cell without ever checking the same direction again (since we know it's unavailable).
One suggestion I was considering is to create a collection and mixing it with Collection.shuffle but I've never used collections before and I don't know how to use that to make the program call 4 methods in a random order that way.
Anyone have a recommendation or a good trick I can use?

Thank you!
21  Game Development / Newbie & Debugging Questions / Interface Programming Newbie on: 2013-02-09 21:58:59
Hello, I'm quite new to programming and I want to be able to get a little better at it.
I don't have too much trouble making the code for what happens but I'm really bad
at making a window that shows everything.
I once got the graphics for a Slot Machine and managed to make it work quite well
but I can hardly make something more interresting than a textfielf and textarea if
I have to do it myself so I was just wondering if someone knows a tutorial that helps
me get started with this.
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.

xsi3rr4x (30 views)
2014-04-15 18:08:23

BurntPizza (27 views)
2014-04-15 03:46:01

UprightPath (42 views)
2014-04-14 17:39:50

UprightPath (24 views)
2014-04-14 17:35:47

Porlus (41 views)
2014-04-14 15:48:38

tom_mai78101 (63 views)
2014-04-10 04:04:31

BurntPizza (123 views)
2014-04-08 23:06:04

tom_mai78101 (222 views)
2014-04-05 13:34:39

trollwarrior1 (189 views)
2014-04-04 12:06:45

CJLetsGame (198 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!