Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
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  Java Game APIs & Engines / Engines, Libraries and Tools / Re: LibGDX SpriteBatch performance degradation on: 2014-08-31 18:26:32
Generally only because it's being called too often. Sometimes it goes particularly slow with some drivers if it's given duff parameters and/or data.

Are you using VBOs?

Cas Smiley

I don't think I am, since I never specified it.  Does SpriteBatch give you that option?  I am aware that it internally uses a Mesh instance, and a Mesh can be toggled to use different rendering methods, including VBOs.

Edit:  Oh, and thanks for showing me the -Xprof argument.  That's probably going to be helpful in the future for me.
2  Java Game APIs & Engines / Engines, Libraries and Tools / Re: LibGDX SpriteBatch performance degradation on: 2014-08-31 18:24:27
Hrm!  I can prevent performance issues by reducing the number of buffers in SpriteBatch!  And the reason for this is...  I don't know!  Like great programmers before me have said, optimizing prematurely is the root of all evil.  I don't want want to continue working on my game without understanding exactly why this code is working.

Let me see if I've got this straight...  Every draw call adds a list of texture data and vertices for later, and a nice default shader program is written for me so I don't have to make one.  Whenever .end() is invoked, that buffered data will be uploaded to OpenGL for rendering.  I am also assuming that the same will happen if the buffers become full.  Both cases will cause the buffers to flush.  In reality, it's adding stuff to a hidden Mesh instance, and then rendering it, which really does the same thing, but in a more modular way.  By reducing the sizes of the buffers, I am increasing the number of draw calls, and making my packets of data smaller.  That sounds bad!

Or is it?

I noticed that if I force the buffer size to be, say, 200, the cpu peaks at about 10% rather than 19%!  I know I probably sound like a guy that doesn't know what he's talking about, and I probably am.  If I need to look further into this, feel free to tell me.
3  Java Game APIs & Engines / Engines, Libraries and Tools / Re: LibGDX SpriteBatch performance degradation on: 2014-08-31 18:05:26
19% CPU usage is not problematic at all (unless you have like a top of the line Xeon with this usage percentage Roll Eyes).

To understand what's going on behind the scenes first you have to understand how a SpriteBatch works: When you're working with modern OpenGL you should be storing your data (vertices, texture coordinates, normals, colors, etc.) in buffers. Sending data to the GPU in buffers and then later rendering them is one of the fastest ways render things today. However, having too much buffers is not healthy for the performance either. That's because draw calls are probably the most expensive calls that you can make on the GPU, and when you have N buffers that you want to render you're going to have to call N draw calls (there are many ways of optimizing this in OGL4.0+ but I'm not going to go into that now) which is obviously slow. Thus, a game developer should always decide how many buffers does he want to use: One VBO per object, grouping together multiple objects based on some property (eg. put all the static meshes into a single buffer, store the dynamic and streamed objects separately) or storing everything in a single buffer.

Each and every one of these has it's ups and downs and you should pick the right approach for your game. For 3D games storing everything in a single buffer is of course not viable, since every time you do a draw call the GPU would have to render EVERYTHING that is in your game. There would be no frustum or occlusion culling, unless you reconstruct the buffer every frame which is obviously really going to hurt CPU performance. However, for 2D games storing everything in a single buffer is perfect: We don't have too many vertices and frustum culling techniques are extremely cheap when working with 2D so we can easily reconstruct the buffer every frame on the CPU without hurting performance too much.

Problem is, every time we need to render something with a different texture than the last time we have to create a new buffer, bind the new texture, store new data in the buffer and send that to the GPU as well as the previous buffer. Of course this is a naive approach since there are many ways to reduce this performance problem, here is two: Texture arrays and texture atlases.

With texture arrays you can have multiple textures' data packed into a single texture object, but this technique has it's own set of problems so I would not recommend using it to you until you learn more about OpenGL.
Texture atlases on the other hand, have very few negatives and they are commonly used in almost all the (if not in every) commercial 2D games. With texture atlases you have multiple textures packed into a single image file, so whenever you want to render something if that thing is on the atlas as well as the previous one there's no need to bind new textures or create new buffers. You can just keep storing the data in the same buffer that you later want to send to the GPU. Notice however, that since you have multiple textures in the same image you can't use simple texture coordinates anymore like (0, 0); (1, 0); (1, 1); (0, 1); Luckily that is not too big of a problem and you can easily calculate the position of your textures in the atlas, or use some kind of texture packer utility and parse it's output.

Hope this helps. Smiley

Ah, well, I do plenty of texture batching, and I created my own sort of TextureAtlas class that loads Textures in batches using the output of a png and txt file.  I'm sure that's not what is causing the issue here.  I suppose this may not be a huge issue after all, but I still don't understand why the cpu uage would slowly go up over time.  Are you saying that I am using too many buffers in my instance of SpriteBatch, and that's what is causing eventual performance loss?
4  Java Game APIs & Engines / Engines, Libraries and Tools / Re: LibGDX SpriteBatch performance degradation on: 2014-08-30 22:16:26
You said that the problem was benign.  Is this supposed to happen?  I'd rather the cpu usage be low than high, even if the perceived performance is good regardless.  I'm not here to melt cpus.  If the problem really isn't important, I'd like to know what's happening, at least.  I have only a little experience in OpenGL, but have since switched to LibGDX becacuse I got sick of it.  I am vaguely familiar with glDrawElements, since I believe I either used that or the array variation at some point when learning the pipeline.  Is there any reason why this method would be slowing down over time?
5  Java Game APIs & Engines / Engines, Libraries and Tools / Re: LibGDX SpriteBatch performance degradation on: 2014-08-29 19:02:40
Seems that whatever method is nglDrawElements, it's using up a considerable amount of time.  By the way, I just tested it, and the cpu goes down after aout 2 minutes inexplicably.  Weird...  Still a problem.
6  Java Game APIs & Engines / Engines, Libraries and Tools / Re: LibGDX SpriteBatch performance degradation on: 2014-08-29 18:35:10
There's not enough information about the argument -xprof online.  Can't seem to figure out how to use it.  Doesn't seem to work when compiling my application to a jar, and I don't really know how to compile without archiving it.  Sorry If I'm a little shaky on command-line java arguments.

Edit:  Did a bit of testing.  Does this suffice?  Seems to work for me.
1  
java -Xprof -jar game.jar


Not sure what the profiling information means, but here it is!

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  
C:\Users\Owner\Desktop\test>java -Xprof -jar game.jar

Flat profile of 0.37 secs (33 total ticks): main

  Interpreted + native   Method
 36.4%     0  +    12    org.lwjgl.openal.ALC10.nalcCreateContext
 30.3%     0  +    10    java.net.NetworkInterface.getAll
  3.0%     0  +     1    java.lang.ClassLoader.findBootstrapClass
  3.0%     0  +     1    org.lwjgl.openal.ALC10.nalcOpenDevice
  3.0%     0  +     1    org.lwjgl.openal.AL.nCreate
  3.0%     0  +     1    java.util.zip.Inflater.inflateBytes
  3.0%     1  +     0    java.lang.ClassLoader.defineClass1
  3.0%     0  +     1    java.io.WinNTFileSystem.canonicalize0
  3.0%     0  +     1    java.lang.ClassLoader$NativeLibrary.find
  3.0%     1  +     0    java.security.Provider.addEngine
  3.0%     1  +     0    java.lang.String.replace
 93.9%     3  +    28    Total interpreted

  Thread-local ticks:
  6.1%     2             Class loader


Flat profile of 97.06 secs (8762 total ticks): LWJGL Timer

  Thread-local ticks:
100.0%  8762             Blocked (of total)


Flat profile of 97.39 secs (8790 total ticks): DestroyJavaVM

  Thread-local ticks:
100.0%  8790             Blocked (of total)


Flat profile of 97.40 secs (8791 total ticks): LWJGL Application

  Interpreted + native   Method
  3.9%     0  +   150    java.lang.Thread.sleep
  1.6%     0  +    60    sun.misc.Unsafe.copyMemory
  1.3%     0  +    49    org.lwjgl.opengl.WindowsDisplay.defWindowProc
  1.2%     0  +    47    org.lwjgl.opengl.WindowsDisplay.nUpdate
  0.9%     0  +    36    sun.misc.Unsafe.getInt
  0.9%     0  +    34    sun.misc.Unsafe.putInt
  0.7%     1  +    25    org.lwjgl.opengl.GL11.nglDrawElements
  0.2%     0  +     8    java.lang.System.nanoTime
  0.2%     6  +     0    sourceProperties.Gravity.update
  0.1%     0  +     4    org.lwjgl.opengl.WindowsContextImplementation.nSwapBuff
ers
  0.1%     0  +     4    org.lwjgl.opengl.WindowsPeerInfo.nChoosePixelFormat
  0.1%     0  +     4    org.lwjgl.opengl.GL11.nglClearColor
  0.1%     3  +     0    java.lang.ClassLoader.defineClass1
  0.1%     0  +     2    org.lwjgl.opengl.WindowsContextImplementation.nCreate
  0.1%     0  +     2    com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.load
  0.1%     0  +     2    org.lwjgl.opengl.WindowsContextImplementation.nMakeCurr
ent
  0.0%     0  +     1    sun.misc.Unsafe.compareAndSwapObject
  0.0%     0  +     1    java.util.zip.Inflater.inflateBytes
  0.0%     0  +     1    org.lwjgl.opengl.GL20.nglUniformMatrix4fv
  0.0%     0  +     1    sun.misc.Unsafe.getLong
  0.0%     0  +     1    org.lwjgl.WindowsSysImplementation.nGetTime
  0.0%     0  +     1    sun.misc.Unsafe.getByte
  0.0%     0  +     1    org.lwjgl.opengl.WindowsDisplay.showWindow
  0.0%     0  +     1    org.lwjgl.opengl.GL11.nglGenTextures
  0.0%     0  +     1    org.lwjgl.openal.ALC10.nalcCloseDevice
 12.0%    20  +   440    Total interpreted (including elided)

         Stub + native   Method
 62.7%     0  +  2403    org.lwjgl.opengl.GL11.nglDrawElements
 11.2%     0  +   431    org.lwjgl.WindowsSysImplementation.nGetTime
  6.1%     0  +   232    java.lang.Thread.sleep
  4.5%     0  +   171    java.lang.Thread.yield
  2.9%     0  +   110    java.lang.System.arraycopy
  0.4%     0  +    15    sun.misc.Unsafe.putByte
  0.1%     0  +     3    sun.misc.Unsafe.compareAndSwapObject
  0.1%     0  +     3    com.badlogic.gdx.utils.BufferUtils.copyJni
  0.0%     0  +     1    java.lang.Thread.currentThread
  0.0%     0  +     1    org.lwjgl.opengl.GL11.nglDepthMask
  0.0%     0  +     1    com.badlogic.gdx.math.Matrix4.mul
  0.0%     0  +     1    org.lwjgl.opengl.GL20.nglVertexAttribPointer
 88.0%     0  +  3372    Total stub

  Thread-local ticks:
 56.4%  4959             Blocked (of total)


Global summary of 97.77 seconds:
100.0%  8824             Received ticks
  0.3%    23             Compilation
  0.0%     2             Class loader

C:\Users\Owner\Desktop\test>pause
Press any key to continue . . .
7  Java Game APIs & Engines / Engines, Libraries and Tools / LibGDX SpriteBatch performance degradation on: 2014-08-29 16:27:53
It seems that my 2D platformer game is becoming slower over time.  I decided to check out LibGDX since it was up to date with newer versions of opengl, runs smoothly, and acts as more of an optional abstraction around the pipeline.  I haven't run into any noticeable performance issues, but I have seen my cpu reach 19% over time.  To be specific, when I first launch the game, it runs quickly and efficiently.  Only about 2% of the cpu is being used at most.  After about 30 seconds, it's 4%.  Then, after a minute, it peaks to about 19%.  It never goes beyoind that number, and the fps never drops.  I can hear my fan going nuts, though, so it is still a problem.

I made a simple but effective performance logger that records the amount of time it takes to complete a task.  After about, say, 60 recordings, since my game's fps is 60, I log a message to a PrintStream regarding the average amount of time it took to complete the task.  I narrowed down where the performance degrades, and it's in LibGDX's SpriteBatch class.  Invocations of end() start to become slow after a while, but I am not sure why.  Here the the method utilizing SpriteBatch that sees performance issues.

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  
   public void render(Matrix4 m, float parentAlpha)
   {
      // Optimizes the grid so that only the tiles that are visible are displayed
      if(optimized)
         optimize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
     
      // Grabs SpriteBatch from globally accessible Renderer
      SpriteBatch batch = Renderer.getSpriteBatch();
     
      // Sets alpha to the one accumulated through the scene graph
      batch.setColor(1, 1, 1, parentAlpha);
     
      // Begins drawing
      batch.begin();
     
      // Renders all tiles within optimized range.  Mins and maxes were determine when optimize() was invoked
      for(int y=minY; y<maxY; y++)
      {
         for(int x=minX; x<maxX; x++)
         {
            TextureRegion reg = get(x, y);
            if(reg != null)
            {
               batch.draw(reg, x*regWidth, y*regHeight);
            }
         }
      }
     
      // Ends drawing
                logger.begin();        // Begins recording the amount of time it takes to complete batch.end()
      batch.end();
                logger.end();          // Ends recording, and outputs the average amount of time it took to complete after 60 invocations.
   }


Ok, not all variables are defined in this example, but I think what is happening here should be clear.  I have a matrix of tiles that I want to render, and the tiles are an array of TextureRegions.  When rendering, I iterate through the matrix from the top left to the bottom right horizontally before vertically.  When I am done rendering this batch, I invoke batch.end().  I have proven that the degredation occurs specifically at the invocation of batch.end(), because the amount of time it takes to do this after about a minute is 17-18 milliseconds, which composes the majority of the aforementioned slowdown.

Why would this method behave like an angel, and then suddenly slow down later?  I can't really focus my logger on a particular part of this method since it's part of LibGDX.  Is there some way that I could be misusing SpriteBatch here, or somewhere else?  I'm still fairly new to LibGDX, so I would not be surprised.

Edit:  I am aware that SpriteBatch's end() method uploads vertices and texture ids to opengl that were gathered earlier.  I feel like somehow, my batch is accumulating vertices/id's/SOMETHING, and perhaps I am forgetting to clear that something.
8  Java Game APIs & Engines / Engines, Libraries and Tools / Re: SpriteBatch setProjectionMatrix woes... on: 2014-08-06 02:51:36
Aaaaand I solve my own problem only after I post something and make myself look like an idiot xD.  I should have extracted the matrix and transformed it BEFORE calling begin/end.  Like this:

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  
package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter;

import scenegraph.*;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Matrix4;


/**
 * Object representing the core of the game.  Which platform it compiles for
 * varies
 * @author William Andrew Cahill
 */

public class GameLauncher extends ApplicationAdapter
{
   // Rendering variables
   private SpriteBatch batch;         // Object that renders all the sprites
   
   // Region to draw
   TextureRegion region;
   
   
   @Override
   public void create()
   {
      // Initializes batch
      batch = new SpriteBatch();
     
      // Stores first image
      region = new TextureRegion(new Texture(Gdx.files.internal("res/entities/wiggles/wigglesIdle.png")));
   }

   
   @Override
   public void render()
   {
      // Clears the screen
      Gdx.gl.glClearColor(1, 0, 0, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
     
      // Begins drawing
      // Gets matrix and copy
      Matrix4 m = batch.getProjectionMatrix();
      Matrix4 c = m.cpy();
     
      // Draws
      m.translate(100, 1, 0);
      batch.begin();
     
      batch.draw(region,0,0);
     
      // Restores matrix
      batch.setProjectionMatrix(c);
     
      // Ends drawing
      batch.end();
   }
}


As you were...
9  Java Game APIs & Engines / Engines, Libraries and Tools / SpriteBatch setProjectionMatrix woes... on: 2014-08-06 02:46:03
I want to render an image at coordinates 100, 50, 0.  Consider the following code...

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  
package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter;

import scenegraph.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Matrix4;


/**
 * Object representing the core of the game.  Which platform it compiles for
 * varies
 * @author William Andrew Cahill
 */

public class GameLauncher extends ApplicationAdapter
{
   // Rendering variables
   private SpriteBatch batch;         // Object that renders all the sprites
   
   // Region to draw
   TextureRegion region;
   
   
   @Override
   public void create()
   {
      // Initializes batch
      batch = new SpriteBatch();
     
      // Stores first image
      region = new TextureRegion(new Texture(Gdx.files.internal("res/entities/wiggles/wigglesIdle.png")));
   }

   
   @Override
   public void render()
   {
      // Clears the screen
      Gdx.gl.glClearColor(1, 0, 0, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
     
      // Begins drawing
      batch.begin();
     
      // Gets matrix and copy
      Matrix4 m = batch.getProjectionMatrix();
      Matrix4 c = m.cpy();
     
      // Draws
      m.translate(100, 50, 0);
      batch.draw(region,0,0);
     
      // Restores matrix
      batch.setProjectionMatrix(c);
     
      // Ends drawing
      batch.end();
   }
}


No matter what transformations I make, it stays in the same place.  I know that there is a draw method in SpriteBatch that lets me specify where to draw it, but I am trying to set up a scene-graph, and that requires me to translate, rotate, etc using SpriteBatch's Matrix4 extracted from batch.getProjectionMatrix().  I can make it look like the image slides across the screen if I remove the line that restores the matrix to it's original form, but I can't make it shift and stay there.  Is my understanding of the projection matrix incorrect?  I always have this problem with LibGDX, but I can never remember how to solve it.  The docs don't really explain its behavior.
10  Game Development / Newbie & Debugging Questions / Re: Teaching Java Game Programming to Children on: 2014-07-04 21:11:14
Similarly, you might also check out Light Bot: http://light-bot.com/hocflash.html

More generally, you can check out the Hour of Code tutorials that are designed to be a little more fun than old-school teaching: http://csedweek.org/learn

It seems to me that the OP simply was not prepared to teach this class. It's not too late to turn it around, OP!

I'd also be curious to hear how you got this gig. Where are you located? I'd love to do something similar, so I'd love any detail you can give us.

To answer your question, I got this job because my roommate worked there last summer, and his employer asked him if he could find other programmers willing to teach.  He was on the athletics side of teaching, but he knew that I was an avid-ish programmer.  Getting the job was pretty easy after that because of the demand for them.

I currently work at ONE of the three TIC sites.  I've learned that I need to remember what it was like picking up programming for the first time, because I keep forgetting to explain what every little piece of syntax means.  Also, when I write example code on the board, even my smarter seniors have trouble realizing that the code I gave them was just an EXAMPLE!  Far too often, they'll complain that they copied everything I wrote, and it still wouldn't run!  Uuuuuggggghhh......  I'm not trying to raise a bunch of code monkeys here!

If you find kids that are just not interested in programming, I recommend that you don't try to teach them Java.  We have a choice in deciding what language we teach, and I recommend that the less motivated students learn Microworlds.  It still warms my heart when I hear the kids say that they WANT to learn Java.

Another thing I've learned is that you don't have your student's attention unless they're looking at you or the board.  Even today, one of my campers kept telling me that he was paying attention, but the exact instant that I continued writing on the board was the instant that he looked at the floor again.  I asked him if he could explain what I just said.  Of course, he couldn't xD.  I'm still talking about my smarties, by the way.  They're geniuses, for sure, but still have their bad days.  I've learned to stay away from visual programming with swing components, because I am just not capable of teaching them something like that within the span of two weeks.

So, yeah.  Creating a main method, basic data types, object types, loops, recursion, and classes are what I am trying to restrict myself too.  This first week, they've almost completed the framework for their grid-based console adventure in which the grid is made out of ascii characters.  I just hope we have enough time next week to finish something up.  It's taking a while to teach abstraction, which is going to be necessary for their game, but they're getting it.
11  Game Development / Newbie & Debugging Questions / Re: Teaching Java Game Programming to Children on: 2014-07-04 20:53:59
I have to figure out how to get the less motivated students to get into programming.
How about Logo? Online here.
It was specifically designed to get less involved students doing some programming without realising it.
They immediately get something to show for their work. Even if it is just a square, they did it!


We actually use Microworlds EX which uses Logo.  It's SUPPOSED to be for the juniors who are 7 - 9.  Our seniors are 11 and up, and the ones I had last session would have probably benefited from learning Microworlds instead of Java.  They were not really that interested in it.  This session is better.  They would rather learn about file processing and console-based programming than making visual games.  They want to know how programming works.  By the way, a session is two weeks for our camp.  One more week with these seniors.
12  Game Development / Newbie & Debugging Questions / Re: Teaching Java Game Programming to Children on: 2014-06-16 23:00:05
Depends on how much you have time and how experienced your audience is. For beginners, forget too complicated systems and games. Teach them variables, if-else, loops and how to grab input and how to display outcome. Then show how to make a simple text based game. Like questions and player must answer A, B or C.

That's for programming, for teaching how to make games I guess it could be better to use programs like Game Maker. Or Flash like I did.


Teach them how to write their own programs for their multiple choice quizes as part of the course. Then challenge them to make a fair quiz to give to their other students, let them use any programming related questions they want and low-ball the total value of their quiz as part of their final assignment grade.

That way they can "give" their classmates extra credit by giving them easy questions, but forces them to think outside the box and write a very simple actually-useful application. Make the majority of the total grade (100%) for the project the actual program they wrote and +10% extra credit the quiz points they get from taking *other* people's quizes with *their* programs.

Ah, sneaky sneaky!  Make them write a quiz for me, and call it a "text based game"!  Hah, well, these kids aren't really graded on their performance.  It's just a summer camp that both advocates physical activity, and tech literacy.  There is no REAL pressure on the students or counselors.  I'm still considering making a basic API that allows game creation to be that much less painful.  I think I can do this.  I just have to figure out what to do with the less-willing students.  I've know that after a few years of programming that you don't have to be a super genius to become a programmer.  A moron can become an elegant coder if he/she is motivated.  Which I am xD  It's all about dedication, and I have to figure out how to get the less motivated students to get into programming.
13  Game Development / Newbie & Debugging Questions / Re: Teaching Java Game Programming to Children on: 2014-06-16 22:53:14
Depends on how much you have time and how experienced your audience is. For beginners, forget too complicated systems and games. Teach them variables, if-else, loops and how to grab input and how to display outcome. Then show how to make a simple text based game. Like questions and player must answer A, B or C.

That's for programming, for teaching how to make games I guess it could be better to use programs like Game Maker. Or Flash like I did.


I just got back from my first day.  It's funny.  I came to the same conclusion today.  I had enough trouble explaining what if-else statements did.  Most of them are not ready to be learning loops and lists.  Still, I feel that know-it-all of my group is.  He already has some experience in programming in other languages, so he's not to hard to work with.  It's the ones that have little experience and motivation to learn Java that make this job tricky.  One of the less experienced ones felt the need to write down every little thing.  That shows that he has a great work ethic, but it takes a while for him to write it down.  I'm glad that he's willing to learn and is patient, though.  I think that I will write a lesson plan that explains all of the basics before I get to any of the harder stuff.  There is another Java counselor that is new like me, so this could benefit both of us.  My goal now is to create as many examples demonstrating the basics of Java as possible all while heavily documenting every line to explain what is happening.  I believe that I can at least create a basic text-based game by the end of next week.
14  Game Development / Newbie & Debugging Questions / Re: Teaching Java Game Programming to Children on: 2014-06-15 19:45:49
Dont underestimate these children, not "I may be, I may not", because children can be quite bright people. I am no puppy games or notch making $$$ off of indie games, but I sir, am I a child; and I have made a halfway decent, but still unfinished, prototype of a game called Project NAH. It may not be the coolest thing ever but it shows that kids can do a thing or two; [showoff] however- I scored 10% higher percentile on average than the average student that goes to one of the hardest prep schools in Illinois and my mommy was so proud Cheesy [/showoff]

As far as teaching them, I seriously think if its possible you should teach them more low level stuff, if they are really serious about it they will enjoy it, they will benefit more from it, and they will have a greater sense of "omg i made something" by the end of everything.


I'm guessing that you are a fan of Minecraft.  I have heard that the majority of the kids I will be teaching are also a fan of that game.  Well, I am as well, of course xD.  So addicting!  Anyway, your post interested me because I used to be a child programmer as well.  Started when I was 11.  I began my programming career making basic games in Flash using ActionScript 2.0.  I never had to deal with low level rendering because everything in flash was a scene graph.  I would always be confounded by advanced programmer's code, even though I considered myself to be a veteran coder.  I didn't know what I was talking about, of course.  These kids likely have no experience at programming in Java, and cramming low level Java2D over the course of one summer might be a little daunting.
15  Game Development / Newbie & Debugging Questions / Re: Teaching Java Game Programming to Children on: 2014-06-15 19:39:12
Is this going to be a school for kids who already know java, and want to make games, or just a general school where kids will make games using java? If its the latter, you should drop the idea of using generics. Besides, there is a huge difference between roles in game development. One might be artist, musician, sound designer, level designer, story writer, lead designer, programmer and probably a lot more.

So what are they learning exactly? Programming? Or game making?

Most of these kids don't know Java yet, but many specifically asked to be taught Java.  This school is an athletics/tech summer camp, and my group is learning game programming.  Other groups are doing digital arts and music making.  We are not collaborating, necessarily.

I don't think utilizing generics should be too difficult.  I'm not teaching them to MAKE generic classes, after all.  Any beginning Java programmer should be able to understand how to use an ArrayList<SomeType> which I will teach them to do before I get to any actual game programming.  The first block of code I wrote will not be something I expect them to write.  I will be writing it.  They just use it, like in the second block.

I think they should be able to set up a JFrame, and create an instance of my GamePanel, which extends JPanel and provides basic management for game objects and rendering.
16  Game Development / Newbie & Debugging Questions / Teaching Java Game Programming to Children on: 2014-06-15 18:33:49
I just got a job about a week ago that will involve me teaching children how to program games this summer.  The juniors are going to be learning MicroWorlds, which is a very basic game making software aimed at children about 7-9 years old.  The seniors I'll be teaching are about 11-12.  They will be learning Java.  I have a reasonable amount of game-making experience using Java, but I've never come across a library that allows making 2D games to be particularly easy for a newbie.  Slick2D is incredibly easy from the perspective of an adult programmer, and LibGDX is alright once you get the hang of it.  Still, I'd like these kids to be able to use something simpler.  Something that already has defined what a game object is, preferably.

I may be underestimating these kids, since I've heard that many of the seniors are quite bright.  I am planning on teaching them how to make basic 2D games using Java2D since I think it would be a hassle to install an external library on each of their machines.  Still, I WANT to define what a game object is for them, and WANT to have those game objects easily attachable to a world.  I also WANT to be able to have those game objects communicate with each other easily.  I might write something like this so that they can access all game objects of a certain type.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public <T> List<T> getAll(Class<T> c)
{
    List<T> list = new ArrayList<>();
    for(GameObject go : gameObjects)
    {
        if(c.isAssignableFrom(go.getClass()))
            list.add((T)c);
    }
    return list;
}


Using this method would be as simple as this...
1  
2  
3  
4  
5  
6  
7  
8  
9  
List<Wall> walls = world.getAll(Wall.class);
List<Collidable> collidables = world.getAll(Collidable.class);
for(Wall w : walls)
{
    for(Collidable c : collidables)
    {
        w.enforceCollision(c);
    }
}


This should make it much easier to get their ideas implemented as quickly as possible.  Since they're young, I'm not expecting them to create anything too cpu-intensive, so such an ugly design would be perfectly suitable and simple for these novices.  Nevertheless, I will expect them to write their own game object implementations.  They will have to write the code for their spaceship, or they will have to write the code for their jumping player.  The basic library I'm writing won't take long to make, and mostly just handles rendering for them as well as attaching game objects to a world.  It also simplifies game object communication.

If anyone has any experience in teaching game programming to children 11-12, or just programming in general, could you tell me if I am I overreacting in assuming that these children will have a hard time understanding Java2D?  Am I making it too easy for them by making this library?  I know another programming counselor is teaching Python to his students using PyGame, although I've never actually used it myself.  I'm assuming that it's much simpler to use for making basic games than making a game straight from Java2D.
17  Java Game APIs & Engines / OpenGL Development / Re: VBOs in LWJGL on: 2014-05-27 01:18:17
I have the successfuls!  My class now appears to function without any quirky behavior.  I had to replace

GL11.glDrawElements(GL11.GL_TRIANGLE_STRIPS, indices.capacity(), GL11.GL_UNSIGNED_INT, 0);

with

GL11.glDrawElements(GL11.GL_TRIANGLE_FAN, indices.capacity(), GL11.GL_UNSIGNED_INT, 0);

to make it draw a quad, and not just a triangle.  Probably going to have to look into how those draw methods work.  Now, to dispose of the Mesh, I just need to delete all of the buffers, and destroy the underlying texture.  Then life should be good forever!
18  Java Game APIs & Engines / OpenGL Development / Re: VBOs in LWJGL on: 2014-05-27 01:06:53
Try replacing

1  
2  
3  
4  
//    (line 124-126)
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, tvbo);
      GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
      GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);


with

1  
2  
3  
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, tvbo);
      GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
      GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);


I could be totally wrong, I don't have this totally memorized.

Woah!  That!  Almost worked!  It actually displayed something!  Three of the verticies of my texture, in fact!  Ah, well, now I have to figure out why THAT'S happening, but it works!  Man, this all reminds me of my assembly class, where type information does not exist, and the program can exit inexplicably due to limited runtime checks.  Can't believe I missed that.  I understand what I did wrong.  Thanks for your help!  I'll make another post once I get this class working...  Or if I fail and need help again Smiley
19  Java Game APIs & Engines / OpenGL Development / Re: VBOs in LWJGL on: 2014-05-27 00:22:31
I maaaaaaay have forgotten to flip the buffers.  I shall see if I can fix this...

Edit:  Ok, so now instead of giving an error message, it just crashes.  Windows forces it to close, and I am given no indication as to why this happens.  Ugh...  Here is my updated code:
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  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
package render;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;
import core.Disposable;
import core.Renderable;
import core.Texture;


/**
 * 2-Dimensional Mesh object that can be rendered.  Uses VBOs to render data.
 * @author William Andrew Cahill
 */

public class TexturedMesh2D implements Renderable, Disposable
{
   // Buffered objects
   private Texture tex;         // Texture to use
   private int vbo;            // Verticies to draw
   private int ibo;            // Index buffer to use
   private int tvbo;            // Texture vbo to use
   
   // Vertex buffers
   private FloatBuffer vertices, texCoords;      // Vertex and Texture coordinates
   private IntBuffer indices;                  // Indices
   
   
   /**
    * Constructs the mesh
    * @param vertices List of vertices to connect to
    * @param texCoords Texture coordinates for mapping
    * @param indices Order in which to connect vertices
    * @param tex Texture to map to Mesh2D
    */

   public TexturedMesh2D(FloatBuffer vertices, FloatBuffer texCoords, IntBuffer indices, Texture tex)
   {
      create(vertices, texCoords, indices, tex);
   }
   
   
   /**
    * Constructs a TexturedMesh with the mesh simply wrapping the entire texture.
    * @param tex Texture to use
    */

   public TexturedMesh2D(Texture tex)
   {
      // Creates vertices
      FloatBuffer vertices = BufferUtils.createFloatBuffer(8).put(new float[]
      {
         0, 0,
         tex.getWidth(), 0,
         tex.getWidth(), tex.getHeight(),
         0, tex.getHeight()
      });
      vertices.flip();
     
      // Creates texture coordinates
      FloatBuffer texCoords = BufferUtils.createFloatBuffer(8).put(new float[]
      {
         0, 0,
         1, 0,
         1, 1,
         0, 1
      });
      texCoords.flip();
     
      // Creates indices
      IntBuffer indices = BufferUtils.createIntBuffer(4).put(new int[]{0, 1, 2, 3});
      indices.flip();
     
      // Creates mesh
      create(vertices, texCoords, indices, tex);
   }
   
   
   /**
    * Creates the mesh
    */

   private void create(FloatBuffer vertices, FloatBuffer texCoords, IntBuffer indices, Texture tex)
   {
      // Checks arguments
      if(vertices == null || texCoords == null || indices == null || tex == null)
         throw new IllegalArgumentException("Arguments cannot be null");
     
      // Stores arguments
      this.vertices = vertices;
      this.texCoords = texCoords;
      this.indices = indices;
      this.tex = tex;
     
      // Creates coordinate vbo
      vbo = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
      GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW);
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
     
      // Creates texture vbo
      tvbo = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, tvbo);
      GL15.glBufferData(GL15.GL_ARRAY_BUFFER, texCoords, GL15.GL_STATIC_DRAW);
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
      System.out.println(texCoords.capacity());
     
      // Creates ibo
      ibo = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
      GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW);
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
   }
   
   
   /**
    * Sets up object pointers before using them
    */

   private void setupPointers()
   {
      // Points to vertices
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
     
      // Points to texture vertices
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, tvbo);
      GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
      GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
     
      // Points to indices
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
   }

   
   @Override
   public void render()
   {
      render(0, 0);
   }

   
   @Override
   public void render(float x, float y)
   {
      // Translates
      GL11.glTranslatef(x,  y,  0);
     
      // Sets up buffer pointers
      setupPointers();
     
      // Binds texture
      tex.bind();
     
      // Draws elements
      GL11.glDrawElements(GL11.GL_TRIANGLE_STRIP, indices.capacity(), GL11.GL_UNSIGNED_INT, 0);
     
     
      // Disables states
      GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
     
      // Translates back
      GL11.glTranslatef(-x, -y, 0);
   }
   
   
   @Override
   public boolean isDisposed()
   {
      // Later, later...
      return false;
   }

   
   @Override
   public void dispose()
   {
      // Later, later...
   }
   
   
   /**
    * Disposes of the TextureMesh2D's underlying resources
    * @param disposeChildren Flag that determines if underlying resources besides the Texture coordinates
    * should be disposed of
    */

   public void dispose(boolean disposeChildren)
   {
      // I'll get to this later...
   }
}


Buffers are now flipped.
20  Java Game APIs & Engines / OpenGL Development / VBOs in LWJGL on: 2014-05-26 22:20:44
AAAAAAH!  I spent hours looking up tutorials trying to understand vbos, ibos, and textures, and I can't even display a simple textured vbo!  I DID manage to get rendering working in immediate mode, but only because it is infinitely more simplistic.

I should probably tell you what I am trying to make.  I am making a class called TexturedMesh that will store a VBO for coordinates, another VBO for texture coordinates, and an IBO for vertex data.

Here is my class:
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  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
package render;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;
import core.Disposable;
import core.Renderable;
import core.Texture;


/**
 * 2-Dimensional Mesh object that can be rendered.  Uses VBOs to render data.
 * @author William Andrew Cahill
 */

public class TexturedMesh2D implements Renderable, Disposable
{
   // Buffered objects
   private Texture tex;         // Texture to use
   private int vbo;            // Verticies to draw
   private int ibo;            // Index buffer to use
   private int tvbo;            // Texture vbo to use
   
   // Vertex buffers
   private FloatBuffer vertices, texCoords;      // Vertex and Texture coordinates
   private IntBuffer indices;                  // Indices
   
   
   /**
    * Constructs the mesh
    * @param vertices List of vertices to connect to
    * @param texCoords Texture coordinates for mapping
    * @param indices Order in which to connect vertices
    * @param tex Texture to map to Mesh2D
    */

   public TexturedMesh2D(FloatBuffer vertices, FloatBuffer texCoords, IntBuffer indices, Texture tex)
   {
      create(vertices, texCoords, indices, tex);
   }
   
   
   /**
    * Constructs a TexturedMesh with the mesh simply wrapping the entire texture.
    * @param tex Texture to use
    */

   public TexturedMesh2D(Texture tex)
   {
      // Creates vertices
      FloatBuffer vertices = BufferUtils.createFloatBuffer(8).put(new float[]
      {
         0, 0,
         tex.getWidth(), 0,
         tex.getWidth(), tex.getHeight(),
         0, tex.getHeight()
      });
     
      // Creates texture coordinates
      FloatBuffer texCoords = BufferUtils.createFloatBuffer(8).put(new float[]
      {
         0, 0,
         1, 0,
         1, 1,
         0, 1
      });
     
      // Creates indices
      IntBuffer indices = BufferUtils.createIntBuffer(4).put(new int[]{0, 1, 2, 3});
     
      // Creates mesh
      create(vertices, texCoords, indices, tex);
   }
   
   
   /**
    * Creates the mesh
    */

   private void create(FloatBuffer vertices, FloatBuffer texCoords, IntBuffer indices, Texture tex)
   {
      // Checks arguments
      if(vertices == null || texCoords == null || indices == null || tex == null)
         throw new IllegalArgumentException("Arguments cannot be null");
     
      // Stores arguments
      this.vertices = vertices;
      this.texCoords = texCoords;
      this.indices = indices;
      this.tex = tex;
     
      // Creates coordinate vbo
      vbo = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
      GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW);
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
     
      // Creates texture vbo
      tvbo = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, tvbo);
      GL15.glBufferData(GL15.GL_ARRAY_BUFFER, texCoords, GL15.GL_STATIC_DRAW);
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
     
      // Creates ibo
      ibo = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
      GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW);
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
   }
   
   
   /**
    * Sets up object pointers before using them
    */

   private void setupPointers()
   {
      // Points to vertices
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
     
      // Points to texture vertices
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, tvbo);
      GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
      GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
     
      // Points to indices
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
   }

   
   @Override
   public void render()
   {
      render(0, 0);
   }

   
   @Override
   public void render(float x, float y)
   {
      // Translates
      GL11.glTranslatef(x,  y,  0);
     
      // Sets up buffer pointers
      setupPointers();
     
      // Binds texture
      tex.bind();
     
      // Draws elements
      GL11.glDrawElements(GL11.GL_TRIANGLE_STRIP, indices.capacity(), GL11.GL_UNSIGNED_INT, 0);
     
      // Disables states
      GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
     
      // Translates back
      GL11.glTranslatef(-x, -y, 0);
   }
   
   
   @Override
   public boolean isDisposed()
   {
      // Later, later...
      return false;
   }

   
   @Override
   public void dispose()
   {
      // Later, later...
   }
   
   
   /**
    * Disposes of the TextureMesh2D's underlying resources
    * @param disposeChildren Flag that determines if underlying resources besides the Texture coordinates
    * should be disposed of
    */

   public void dispose(boolean disposeChildren)
   {
      // I'll get to this later...
   }
}


I had to implement a lot of code before I could even think of testing it, so I'm not surprised that nothing shows up on my screen.  I don't even know where to look in order start fixing it, though.  Help?

Edit:  When testing, I use the constructor in which only the Texture is supplied.  I made a Texture class from scratch, and there haven't been any problems with it yet.  Oh, and a shout out to theagentd for helping in this post regarding binding textures: http://www.java-gaming.org/index.php?topic=25516.0  Helped me out a lot.

Edit2:  When I call GL11.glGetError(), I get an error code of 1285 which means out of memory.  Hrm...  It happens after GL11.glDrawElements(GL11.GL_TRIANGLE_STRIP, indices.capacity(), GL11.GL_UNSIGNED_INT, 0);
21  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Shadows. on: 2014-05-04 21:56:20
My question was more whether you want to give the models shadows based on light direction (which is pretty easy) or want them to cause shadows casted to something else, which is what you mean.
This is a little bit more complicated. Did you look into FBOs?

Uh, I don't understand the difference.  xD  I did not look into FBO's. although I've heard of them.  Light based shadow casting sounds fine, though.

Edit: Oh, uh, I think I already basic shading on my models.  Yes, what I want is to cast shadows onto other models in a way that is as painless as possible.  I just looked into FBO's (Frame buffer objects, correct?), and from what I can see, it is an object that renders offscreen before being rendered on screen.  How does this apply to shadows?
22  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Shadows. on: 2014-05-04 19:51:11
I'm hoping for something like this:




The shadow on the pokemon is casted on the ground, and not itself.  I'm assuming this is to increase performance, which is what I'm looking for.  I don't need anything fancy.  Just some basic shadows so the player knows when the character is rooted to the ground.  I know that Jmonkeyengine has something like this, but alas, I decided to work with LibGDX for its portability.
23  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Shadows. on: 2014-05-03 21:03:15
Shadows on the model or shadows in the whole scene?

I suppose shadows on a particular model.  I would like entities to cast shadows on an environment model, but not on themselves or other entities to keep the performance up.
24  Game Development / Newbie & Debugging Questions / [LibGDX] Shadows. on: 2014-05-03 20:50:13
So, I finally figured out how to export 3D models from Blender, and successfully load them into LibGDX.  My question is, is it possible to cast shadows with LibGDX that doesn't require me understand OpenGL extensively?  I don't want to have to use many classes outside of Environment, ModelBatch, etc for this.  Also, if this is possible, I'd like to selectively cast a shadow on certain surfaces.  Is there a painless way to do this in LibGDX?
25  Game Development / Newbie & Debugging Questions / Re: LibGDX import .obj and .g3db not showing textures on: 2014-05-02 03:41:48
I figured it out.  After exporting from blender, I have to convert the .fbx file to a .g3db file using fbx-con.  I forgot to include the command line argument -f when converting.  I SHOULD have typed...

fbx-conv -f wigglesModel.fbx

instead of...

fbx-conv wigglesModel.fbx
26  Game Development / Newbie & Debugging Questions / Re: LibGDX import .obj and .g3db not showing textures on: 2014-05-01 00:22:10
Try multiplying all your UV normalized coordinates by -1

Ah, ok, so it's something to do with how it's created in Blender.  Please excuse my ignorance, for I am new to Blender and LibGDX, but where can I find that in the UV editor?  Scratch that, what does multiplying the UV nomalized coordinates mean, exactly?  Will it flip the image in Blender?  I want what I see in Blender to be what I see when I import it into LibGDX, or at least, roughly the same.

Edit: I want to specify that the model looks fine in Blender, but is flipped in the LibGDX rendering.
27  Game Development / Newbie & Debugging Questions / Re: LibGDX import .obj and .g3db not showing textures on: 2014-04-30 20:40:10
I finally got it to work!  It may have been because my UV mapping went outside the borders of the texture I was using.  I still have one problem, though.  The texture is applied upside down!  How can I fix this?
28  Game Development / Newbie & Debugging Questions / LibGDX import .obj and .g3db not showing textures on: 2014-04-26 02:22:34
I have been spending hours trying to figure this out, but no tutorials that I've found have explained why this might be happening.  I just started 3D modeling in Blender, and I'm finally starting to understand how to created models.  I even managed to map a texture to my model in the program.  The problem is importing the model into LibGDX.  Whenever I do, the texture just doesn't load.  Here's a picture of what happens when I try to load my models:



Of course, a face texture should show up when there is a big rectangular blob.  This is what the model looks like in Blender:


Here is a copy of my blender file, and a couple of exported versions if anyone is interested in sifting through my files:

http://download1481.mediafire.com/obe8ke5zc1ag/17y9s20c8nl2onv/Models.zip

Last, but not least, here is a copy of my rendering code:
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  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
package display;
import java.util.ArrayList;
import java.util.List;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
import com.badlogic.gdx.math.Matrix4;

import util.ResourceManager;

/**
 * Main screen used by project
 * @author William Andrew Cahill
 *
 */

public class DisplayScreen implements Screen
{
   // 3D environment variables
   private DisplayGame game;               // Reference to game
   private Environment environment;         // Environment of models
   private ModelBatch mBatch;               // Batch used for rendering models
   private PerspectiveCamera cam;            // Camera used
   private CameraInputController controller;   // Camera controller
   private AssetManager manager;            // Asset manager
   
   // Etc
   private List<Model> models;               // List of models loaded
   private List<ModelInstance>   instances;      // List of model instances loaded

   // Loading flag
   private boolean loading;
   
   /**
    * Constructs a DisplayScreen
    * @param game Game creating this Screen
    */

   public DisplayScreen(DisplayGame game)
   {
      // Keeps reference of game
      this.game = game;
     
      // Constructs fields
        mBatch = new ModelBatch();
      environment = new Environment();
      environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, .5f));
        environment.add(new DirectionalLight().set(0.4f, 0.4f, 0.4f, -1f, -0.8f, -0.2f));
       
        cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        cam.position.set(0f, 5f, 10f);
        //cam.lookAt(0,0,0);
        cam.near = 1f;
        cam.far = 300f;
        cam.update();
       
        controller = new CameraInputController(cam);
        Gdx.input.setInputProcessor(controller);
       
        // Loads main model
        manager = new AssetManager();
        manager.load("models/wigglesModel.g3db", Model.class);
        loading = true;
       
        // Constructs empty lists of models and their instances
        models = new ArrayList<Model>();
        instances = new ArrayList<ModelInstance>();
   }
   
   
   /**
    * Finishes loading
    */

   private void doneLoading()
   {
        // Loads models
        models.add(manager.get("models/wigglesModel.g3db", Model.class));
       
        // Particular instance
        ModelInstance instance;
       
        // Adds instances
        instance = new ModelInstance(models.get(0));
        instances.add(instance);
        instance = new ModelInstance(models.get(0));
        instance.transform.translate(5, 0, 0);
        instances.add(instance);
        loading = false;
   }
   
   @Override
   public void render(float delta)
   {
      // Brings in data to render whenever ready
      if(loading && manager.update())
         doneLoading();
      // Updates controller
      controller.update();
     
      // Camera clear data
      Gdx.gl.glViewport(0,  0,  Gdx.graphics.getWidth(),  Gdx.graphics.getHeight());
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
     
      // Begins rendering
      mBatch.begin(cam);
      mBatch.render(instances, environment);
      for(int i=0; i<instances.size(); i++)
         instances.get(i).transform.rotate(0, 1, 0, 1);
      mBatch.end();
   }

   
   @Override
   public void resize(int width, int height)
   {
     
   }

   
   @Override
   public void show()
   {
     
   }

   
   @Override
   public void hide()
   {
     
   }

   
   @Override
   public void pause()
   {
     
   }

   
   @Override
   public void resume()
   {
     
   }

   
   @Override
   public void dispose()
   {
      mBatch.dispose();
        instances.clear();
        manager.dispose();
   }
}


Halp?
29  Game Development / Performance Tuning / Re: Default JVM arguments for a particular jar? on: 2014-03-28 17:00:41
Any game will break when users start renaming files. Don't waste time on it.

Sure, if they rename internal files you're out of luck. But I'm talking about renaming a single runnable file, which is probably pretty common.
I've never heard of anyone doing that, and I've been surrounded by idiots for years.

Cas Smiley

I think I'm probably being unclear. I think what the OP is talking about is creating a single runnable .jar file that users can download. I can see a situation where, for example, a new version of the jar is released, and the user downloads it to the same place as the old one. The OS will probably append a (2) or something to the jar, or the jar will contain _v1.2.3 in the name. The user might think that's ugly and just want to have Game.jar somewhere, so he renames it. I'm not talking about getting into the internal files of the game, just the main shortcut that the user is actually going to use. It seems like a common enough case to worry about, especially since it's a one line fix!

Although this is all happening in theoretical land and the OP's code was just an example anyway, so I'm probably just being pedantic.

I'm mostly just writing this code for myself.  I'm not so noble as to write this code to make someone ELSE's life easier!  What kind of guy do you think I am?  xD  Yes, this is for my own purposes in the event that I want to make a particular game that runs with certain JVM arguments.  In my opinion, there should be a file in the jar that lets you specify this instead of doing this crazy indirection.  Even worse is having the user fire up a jar from the command line.  No everyday user should have to do that anymore!
30  Game Development / Performance Tuning / Re: Default JVM arguments for a particular jar? on: 2014-03-26 22:18:36
Oh!  You're talking about programming users.  This was just an example!  No need to do anything too fancy.  Just replace "jarlie.jar" with something more... suitable...
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.

PocketCrafter7 (14 views)
2014-11-28 16:25:35

PocketCrafter7 (9 views)
2014-11-28 16:25:09

PocketCrafter7 (10 views)
2014-11-28 16:24:29

toopeicgaming1999 (76 views)
2014-11-26 15:22:04

toopeicgaming1999 (67 views)
2014-11-26 15:20:36

toopeicgaming1999 (16 views)
2014-11-26 15:20:08

SHC (30 views)
2014-11-25 12:00:59

SHC (28 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (28 views)
2014-11-24 19:59:16
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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