Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
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] 2 3 ... 6
1  Game Development / Newbie & Debugging Questions / Re: Identifying Subclasses on: 2014-04-15 12:35:51
if(spell.getClass() == Fire_Spell.class){
     doStuff();
}

or

spell.getClass().isAssignableFrom( Fire_Spell.class )

or

spell instanceof Fire_Spell
2  Game Development / Newbie & Debugging Questions / Re: Vertex shader on: 2014-04-11 10:30:19
Another very good walk-through for OpenGL shaders (amongst other things):  http://www.arcsynthesis.org/gltut/
3  Game Development / Newbie & Debugging Questions / Re: OpenGL variable names on: 2014-03-31 10:41:52
Out of pure interest, where do these standards come from? Is it something you learn whilst on the job, or studying perhaps?

I guess it's generally organic: someone comes up with a good idea for a standard, others think it's good and adopt it, eventually it becomes the 'standard'.

Probably the best example I can think of professionally was [url url='http://en.wikipedia.org/wiki/Hungarian_notation']Hungarian Notation[/url] which cleverly solved a problem and pretty much became the de-facto standard for parameter/variable names back in my C days.

Quote
This is one of the downsides of being an armchair programmer; I don't get nor seek much exposure to these things.

I don't think this matters too much so long as you stick to your own conventions.
4  Game Development / Newbie & Debugging Questions / Re: OpenGL variable names on: 2014-03-29 09:38:48
Don't think it's a silly question: good conventions can only be a good thing, both for yourself and others (if you're sharing shader code with others).

For my personal projects I use the following prefixes:

gl_       These are pre-defined by GLSL, e.g. gl_Color
g_        Global data that is always present should the shader choose to use it, e.g. g_modelview, g_elapsed
m_       Material properties, these are shader parameters set by materials at each node in the scene or via animation, e.g. m_rotationAngle, m_Colour
in_       Also use in_ as a prefix for the various incoming vertex attributes.

I believe JME3 has a similar scheme.

- stride
5  Java Game APIs & Engines / Engines, Libraries and Tools / Re: modify the contents of VBO on: 2014-03-28 17:51:03
Always use
glBufferSubData
to update the entire data. It just updates the data whereas glBufferSubData will delete the previous data, allocate new memory and then copy the data. With
glBufferSubData
there is some increase in performance since the same memory will be reused.

I assume you meant
glBufferData
in the above (where I've struck-out).

</pedantry> Wink
6  Java Game APIs & Engines / Engines, Libraries and Tools / Re: modify the contents of VBO on: 2014-03-27 18:23:02
It's tricky to work out what the problem is without seeing the 'loop' where these methods are being invoked or understanding what you're trying to achieve.

Is renderInitStart only invoked once?  If so, why is the glBufferSubData call there?  If it is called on every frame then you will need to move the glBufferSubData call after you've bound the VBO (I think calling methods on the default VBO is undefined but don't quote me on that).

i.e.

init:
- allocate the buffer
- bind
- glBufferData to initialise VBO (if required)

on each frame:
- bind the VBO
- glBufferSubData to update the VBO with the new vertices
- draw it

after each frame:
- update the vertices
7  Java Game APIs & Engines / Engines, Libraries and Tools / Re: modify the contents of VBO on: 2014-03-27 17:03:06
The glBufferSubData method works similarly to glBufferData.
You might also want to look at the usage hint you provide when initially uploading data using glBufferData (the last argument).
8  Discussions / General Discussions / Re: Programming Careers and Life Lessons... on: 2014-03-27 16:02:21
There was an interesting article on the beeb recently about job satisfaction:  http://www.bbc.co.uk/news/magazine-26671221

I was slightly surprised that software development was fairly middling - personally, in my experience software/IT 'stuff' is considerably more interesting than almost all of my friends jobs, is considerably better paid, and (touch wood) I've never had any problems finding work.
9  Java Game APIs & Engines / OpenGL Development / Re: OpenGL enumerations on: 2014-03-26 16:35:11
Quote from: gouessej
OpenGL-ES can be used under GNU Linux too, for example on the Raspberry Pi. The engine backends based on LWJGL work that way because as far as I know it provides no windowing toolkit compatible both with Android and desktop environments which isn't the case of all engine backends and that's why it's possible to use the Raspberry Pi with JMonkeyEngine without making a separate native renderer based on its Android GL backend.

Cool I didn't know that.  Couple of my work colleagues have Raspberry Pi's that they're fiddling with, will have to target that as well.
10  Java Game APIs & Engines / OpenGL Development / Re: OpenGL enumerations on: 2014-03-25 16:04:38
I have a platform-agnostic core engine that is extended by platform-specific 'back-ends' for Android and LWJGL.
Why do you need to do that? Doesn't LWJGL support Android??

No, or at least not yet AFAIK.

LWJGL nicely wraps up the underlying OpenGL APIs (and provides some other stuff such as display and mouse/keyboard device management).
Android has this stuff as part of it's core API (depending on version ofc) so they're sort of mutually-exclusive.

I believe most (all?) other libraries/engines use the same approach: LWJGL for Linux / Windows / Mac and OpenGL-ES for Android.
11  Java Game APIs & Engines / OpenGL Development / Re: OpenGL enumerations on: 2014-03-24 15:22:56
Cool, assumed they were constant across all implementation but just wanted to check before I go ahead.
Ta
Smiley
12  Java Game APIs & Engines / OpenGL Development / OpenGL enumerations on: 2014-03-24 14:17:20
I have a platform-agnostic core engine that is extended by platform-specific 'back-ends' for Android and LWJGL.  One aspect of this design that I can't make up my mind on is mapping of the various enumerations in the core part (e.g. primitive types, texture filters, etc) to the corresponding OpenGL constants in the back-end implementations (e.g. GL_TRIANGLE_STRIP, GL_CLAMP_TO_EDGE, etc).

Here are the approaches I've considered so far:

1. Map enums to constants in each back-end

Each back-end implementation is responsible for mapping the enumerations to the constants.  Easy to do using a switch statement, but laborious and possibly error-prone to implement (temptation to cut-and-paste), particularly irksome for some of the larger sets such as blending functions, also adds slight over-head of constantly having to perform the mapping.

2. Hard-code OpenGL constants in the core engine

Assume that the constants are the same across all OpenGL implementations (Android and LWJGL) and hard-code them in the core engine - Is this assumption valid?

(Could probably minimise the hard-coding in most cases by using just one value and the ordinal() of the enum since most OpenGL constants are contiguous).

3. Dodgy reflection lookup of OpenGL constants

Use some devious reflection logic to lookup the OpenGL constants by name, e.g. take the enumeration name(), prepen GL_ and reflect through the static GL classes to find the matching constant - Works but feels dirty!

So:

Any other approaches I've not thought of?
Any opinion on the best approach?  (I'm inclined to #2 since that seems the least effort / risk)

Cheers for any thoughts.

- stride
13  Java Game APIs & Engines / OpenGL Development / Re: LWJGL library path for Eclipse on: 2014-03-23 13:35:25
Quote from: SilverTiger
...

That suggestion works nicely, in fact I have a custom JUnit test-runner that creates a LWJGL display so there is an active OpenGL context for the tests to use.

One slight change is that you have to set a string parameter as the property:

1  
      System.setProperty( "org.lwjgl.librarypath", new File( "target/natives" ).getAbsolutePath() );


i.e. the absolute path at the end.

Would you mind posting your maven config? I am currently bothering with the same thing but I can't get it to run for some reason :/

Sorry hadn't noticed this reply, here's an extract from the POM:

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  
   <properties>
      <lwjgl.version>2.9.0</lwjgl.version>
   </properties>

   <build>
      <plugins>
         <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
               <source>1.7</source>
               <target>1.7</target>
            </configuration>
         </plugin>
         
         <plugin>
            <groupId>com.googlecode.mavennatives</groupId>
            <artifactId>maven-nativedependencies-plugin</artifactId>
            <version>0.0.7</version>
            <executions>
               <execution>
                  <id>unpacknatives</id>
                  <phase>generate-resources</phase>
                  <goals>
                     <goal>copy</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
               <forkMode>once</forkMode>
               <argLine>-Dorg.lwjgl.librarypath=target/natives</argLine>
            </configuration>
         </plugin>
      </plugins>
   </build>


Hope this helps.

- stride
14  Discussions / General Discussions / Re: Ever forget how your own code works? on: 2014-03-12 17:33:47
Lot of good comments (pun intended) in this thread.  Grin

I'll throw one more in: using comments to 'paragraph' code.

Example taken from one of my projects:

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  
...

// Create node for sky-box
final Node root = new Node( "skybox" );

// Construct sky-box
final CubeBuilder cubeBuilder = new CubeBuilder( MeshLayout.create( Primitive.TRIANGLES, "V", false ) );
final MeshBuilder meshBuilder = cubeBuilder.create( size );
meshBuilder.build();
final AbstractMesh mesh = sys.createMesh( meshBuilder );
root.setRenderable( mesh );

// Create material
final MutableMaterial mat = new MutableMaterial( "skybox" );
root.setMaterial( mat );

// Load texture images
final ByteBuffer[] buffers = new ByteBuffer[ paths.length ];
for( int n = 0; n < buffers.length; ++n ) {
    final BufferedImage image = imageLoader.load( paths[ n ] );
    buffers[ n ] = TextureLoader.toBuffer( image, false );
    ...
}

...


Obviously small, concise methods are better, but in cases where you have a long, linear method (like the above) and there's little benefit in splitting it into private helpers, this approach breaks the code into easy-to-follow chunks (especially if you're using an IDE with nice syntax colouring).  The comments mean you can scan through the code relatively quickly to find the bit you're after or to get an understanding of what's going on.

15  Discussions / General Discussions / Re: Ever forget how your own code works? on: 2014-03-12 11:50:06
Agree with previous posters - I've learnt (the hard way) that comments are your friend, even if the code you're writing is only ever going to be seen by your own eyes, it's worth having the mindset that you're writing code for someone else.

Unit-tests are also good documentation, essentially they explain how the code is to be used (as well as obviously testing it works!), which is a good reminder when you come back to it and think WTF!
16  Games Center / WIP games, tools & toy projects / Re: "NXBG" Hexagon-Multiplayer-Tactic-Game on: 2014-03-11 12:30:32
Looks really good.
Am interested to see what you have in mind for building structures and how they affect the game.
Keep up the good work Smiley
17  Discussions / General Discussions / Re: Making everything by yourself. And loving it! on: 2014-03-10 12:25:55
Different strokes for different folks Smiley

If your interest is purely in creating a great looking game without getting too deep into the nitty-gritty of OpengL, LWJGL, etc. then using something like libgdx is a no-brainer.

If you do want to get into the nitty-gritty then crafting your own 'engine' is a great way to learn.

I'm definitely in the later camp.  OK so the stuff I build is purely for my own interest and will almost certainly never see the outside world, but as a couple of other posters have noted, it's a hobby.

That said I think the 'reinventing the wheel' point is still valid - I could (for example) write my own code-generated Java API from the underlying C-based DLL, but LWJGL does that, it's tried and tested, so I use that.  Ditto logging.  Ditto image loading libraries. etc.
18  Games Center / Showcase / Re: [Libgdx - Android] Linky Dots on: 2014-03-06 10:43:32
Nice fun game, good work Smiley
19  Java Game APIs & Engines / OpenGL Development / LWJGL library path for Eclipse on: 2014-03-03 11:49:00
To run an application or unit-test using LWJGL one has to set the java.library.path VM parameter to point to a directory containing the native DLLs.

I have this working fine for my maven build on the command line using a surefire plugin, but it would be nice to get it working within Eclipse.  Obviously I can set the VM parameter in the run configuration but it's painful, especially if I'm writing unit-tests: every test has to have its own run config that I have to set manually.

Done some googling, I can find lots about setting this up for a maven build but not for Eclipse itself.  Get the feeling I'm missing some cunning trick - is there some way to set this 'globally' for an Eclipse project? 

- stride
20  Game Development / Newbie & Debugging Questions / Re: Array within an array on: 2014-02-28 12:55:26
I assume Object_Control.Vegetationarray is a collection such as an ArrayList?

Essentially what the for loop is attempting to do is modify the collection at the same time you are iterating over it, hence the exception.

Two ways round this:

1. Get an iterator from the collection and use Iterator.remove()  (not supported by all collections mind and probably not the best approach for this case anyway).

2. Create a new list of objects to be removed and then remove them in a second step.

i.e.

1  
2  
3  
4  
5  
6  
7  
List<Vegetation> removed = new ArrayList<>();
for(...) {
    for(...) {
        if( ... ) removed.add( c );
    }
}
Object_Control.Vegetationarray.removeAll( removed );


- stride
21  Games Center / Showcase / Re: [Android] Hard Riddle on: 2014-02-26 15:27:47
Nice little puzzler - though you weren't joking when you said some of them were hard! Wink
As a previous poster said the ads causing the app to resize is a bit annoying.
Currently stuck at level 10...  Clueless
Nice work.
22  Discussions / Miscellaneous Topics / Re: PlanetsĀ³ - a 3D open-source voxel-based RPG on: 2014-02-26 00:53:41
Just wow! in terms of reaction to the video.
Please tell me you're going to actually have 6-sided cubic planets because that would be quite fun!
23  Game Development / Newbie & Debugging Questions / Re: When to split a class, when to keep it all as one. on: 2014-02-25 17:22:49
Quote
...At first, they were pretty well encapsulated, but as my project has advanced, they have all become so intertwined together...

Yeah it happens, especially if you're 'developing' your design at the same time as developing the code.  Sometimes it's good to take a step back and do your own review of your design (which it sounds like you have), often I'll do this when I've completed some new feature or change.

Quote
...Many of their major functions are extremely dependent on using getters/setters to pass information to each other...

So my question is, are these signs I should just merge the 2 classes together? They talk to each other so much they're both basically useless without the other.

It sounds like you've essentially created two http://c2.com/cgi/wiki?GodClass  Wink

Rather than debating splitting or joining your two main classes, you might want to consider splitting out the 'model' code from the controllers and make your project more MVC http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

Lots of small, simple classes with clearly defined responsibilities are easier to maintain and test.

You mention a camera, that might be a good candidate for a model class that is controlled by the PlayStateController.  A map model might also be worth considering.

Just some random thoughts, hope it helps.

- stride
24  Game Development / Newbie & Debugging Questions / Re: Multiple lights PHONG on: 2014-02-25 10:53:34
Been a while since I've used the fixed-function methods, but:
1  
2  
3  
FloatBuffer lmKa = BufferUtil.asFloatBuffer(0.0f, 0.0f, 0.0f, 0.0f);
        lmKa.flip();
        glLightModel(GL_LIGHT_MODEL_AMBIENT, lmKa);


sets the ambient light to black?  Maybe that's the problem?
25  Game Development / Newbie & Debugging Questions / Re: Loading a map chunk BEGINNER QUESTION on: 2014-01-21 13:23:23
You didn't say what the problem was, but looking at the code I'm guessing it's an IndexOutOfBounds exception.

You're using tileX/Y as the array indices when you're inserting a tile into chunks, but they're the indices of the 'world' tiles array, instead they should be 0..20 range.

i.e. something like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
...

for( int x = 0; x < 20; ++x ) {
   // Calc world X coord
  final int tx = location.getX() + x;
   if( ( tx < 0 ) || ( tx >= width ) ) continue;

   for( int y = 0; y < 20; ++y ) {
      // Calc world Y coord
     final int ty = location.getY() + y;
      if( ( ty < 0 ) || ( ty >= height ) ) continue;

      // Calc 1-D index into world array
     final int idx = ty * width + tx;
      chunk[ x ][ y ] = tiles[ idx ];
   }
}


Any tiles at your location that are outside of the world will be null.

This assumes you know the width and height of the tiles array (easy to work out presumably from your loader).

It also has the added bonus that you don't need to iterate through the entire world tiles array to pick out the 20x20 you want.


Hope this helps.

- stride
26  Game Development / Newbie & Debugging Questions / Re: [SOLVED] Where are the texture coordinates going wrong? on: 2014-01-15 10:40:15
OpenGL generally needs to have images inverted, you'll see that 'flip' option in most engines or libraries (including my own custom stuff that does it by default).
Glad you got it sorted.
- stride
27  Game Development / Newbie & Debugging Questions / Re: Where are the texture coordinates going wrong? on: 2014-01-14 18:23:18
Thanks for the tips on performance Smiley I'll keep that in mind when I'm cleaning up code.

The performance is a bonus, I was thinking more about maintainability - be a lot easier to change and fix the code if it's neater.

Quote
As for the texture loader, I'm using slick-util, so I wouldn't think it would be anything with that. I guess you never know though, this is the "TextureImage" class

Never used Slick but it's unlikely to be a problem with that as you say.  Maybe try using the 'flip' parameter in getTexture()?  (though it doesn't look like that's the problem)
28  Game Development / Newbie & Debugging Questions / Re: Where are the texture coordinates going wrong? on: 2014-01-14 17:44:13
The 'seams' look to be there now but are way fatter than the one in Blender, maybe it's something to do with how you're loading the texture image?  Can you post that code as well.

As an aside that's a lot of line.splits there Wink, suggest use some intermediate variables: your code will be a lot cleaner and therefore easier to read and maintain, plus a little faster to load too.
29  Java Game APIs & Engines / OpenGL Development / Re: Normal for glClearColor and glClear to be slower than the actual rendering? on: 2014-01-10 16:23:16
2. No, I'm not using vsync. I still get over 200 FPS with this code but I just thought this anomaly was kind of strange, like it shouldn't be happening.

Agreed it's very odd, bit of googling reveals a few other people have had vaguely similar issues but there doesn't appear to be any consensus.
Maybe some other forumistas can suggest why this is happening?
30  Java Game APIs & Engines / OpenGL Development / Re: Normal for glClearColor and glClear to be slower than the actual rendering? on: 2014-01-10 15:44:53
Couple of possibilities spring to mind:

1. It's possible that GL is queuing the commands and only flushing when glClear() gets called - unlikely, though I have seen other odd 'bottle-necks' when profiling before.  Might be worth adding glFlush() at the end of the rendering code?  (or would swapping the buffers force the flush anyway?)

2. Are you using vsync?  It might just be waiting for the sync before starting the clear?

- stride

Pages: [1] 2 3 ... 6
 

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 (12 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (182 views)
2014-04-01 02:16:10
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

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