Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (843)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / JOGL Development / RLE compression for textures on: 2008-12-26 09:46:05
I have a set of textures to display (16384x8192 when combined) that consume too much memory to be practical.  Standard DXT compression won't be enough here.  Many of their texels are the same color however.  In theory, if I could compress the textures with run-length encoding it would dramatically reduce their required memory.

I'm not aware of anything in opengl that does this, so I was thinking of trying to do it crudely with a fragment shader.  For each horizontal line on an uncompressed texture, I would create a short 1D texture with a repeating pattern of a texel encoding the color to display and a texel encoding how many texels that color extends for in the uncompressed texture.  Let me elaborate:

(Assume I'm only dealing with a single color channel here)
Here are the first 15 texels of the 1st line of a texture: 1 1 1 1 5 5 6 28 28 28 28 28 28 28 28
Compressed form: 1 4 5 2 6 1 28 8

The bold number indicates the color, and the following underlined number represents how many texels that color is repeated in the uncompressed texture.  As you can see the "compressed" sequence can be much smaller than the normal sequence if it has very long sequences of the same color.

In a fragment shader, I would be able to calculate the index of the desired texel in the hypothetical uncompressed texture if I'm not mistaken.  I could then iterate through the compressed texture until I reach the desired texel data.  I'm concerned about whether all of this texture accessing is feasible and how this eliminates the nice automatic mipmapping/texture filtering.

Is there anything that I might have overlooked when thinking of this approach?  Is it even a good idea?  Is there a better approach (or even just a different one) that you can think of?  I should probably mention that I am planning to alter these textures slightly from time to time, but they will always have large areas of the same color at any instance.
2  Java Game APIs & Engines / JOGL Development / Re: making DDS files, with mipmaps included, using TextureIO.write on: 2008-11-10 02:52:59
I think I found the answer when I was perusing the TextureIO source code:

"Any mipmaps for the specified texture are currently discarded when it is written to disk, regardless of whether the underlying file format supports multiple mipmaps in a given file." (from a comment above the write method)

Given this situation, would anyone have recommendations on how to write DDS files with mipmaps from textures?
3  Java Game APIs & Engines / JOGL Development / making DDS files, with mipmaps included, using TextureIO.write on: 2008-11-10 02:36:38
I am unclear whether the write method of TextureIO is capable of writing DDS files with mipmaps embedded in the file.

The following is the code I have:
TextureData texData = TextureIO.newTextureData(new File("images/test.png"),true,null);
Texture tex = TextureIO.newTexture(texData);
TextureIO.write(tex,new File("images/"));

What the code does to my understanding:
line 1) This reads a 1024x1024 .png file and makes a TextureData object out of it.  Mipmaps are generated automatically by the chosen boolean.
line 2) Changes the internal format to compressed DXT1 which stores the data with 4 bits per pixel.
line 3) Makes a Texture object out of the TextureData.
line 4) Writes out a .dds file using the Texture Object.

The resulting .dds file is a 1024x1024 image with no mipmaps in it.  Its file size is 512kb (just the base level image) as opposed to 682kb (base image plus all mipmap levels).

My intention is to automate the conversion of many .png files to .dds and have that functionality embedded into a program I am writing.

Am I missing something or does the TextureIO class not have the capability of saving mipmaps with the DDS files it writes?
4  Java Game APIs & Engines / JOGL Development / Re: how does one use normal maps? on: 2008-07-03 00:30:34
After the  shader creation block of code I included these lines:
IntBuffer log1 = IntBuffer.allocate(1);

IntBuffer log2 = IntBuffer.allocate(1);

IntBuffer log3 = IntBuffer.allocate(1);

They each return the number 1 which is equivalent to GL.GL_TRUE

Is this what you meant?  It seems to me that there isn't any useful information in here or perhaps I just don't know how to interpret it.

edit: After messing around with the code, I realized that the stuff in the init method is fine and I was doing something wrong with the ordering in the display method.  Apparently I misunderstood how/when this fragment shader does what it does.  Since there wasn't much interest in this thread, I won't bother posting the details.  Thanks for the help you gave Orangy Tang.
5  Java Game APIs & Engines / JOGL Development / Re: how does one use normal maps? on: 2008-07-02 22:52:48
I still haven't found any jogl shader resources, but I have been trying my best to work through the examples in C which is a little slow having never learned C.  I seem to be in the same spot that I was when I last posted (I can't figure out how to get the shader to interface with my jogl program).

Here is what I have in my attempt to color an otherwise red quad blue via a fragment shader:

I have made a class that implements GLEventListener and inside the init(GLAutoDrawable) method I have this among other things:
int shaderProgram = gl.glCreateProgram(); //this int is available to all methods in the class
int fragShader = gl.glCreateShader(GL.GL_FRAGMENT_SHADER);
   BufferedReader fragShaderReader = new BufferedReader(new FileReader("fragShader.glsl"));
   String fragShaderSource = "", tempFragSCR;
   while((tempFragSCR = fragShaderReader.readLine()) != null)
      fragShaderSource += tempFragSCR + "\n";
   String[] fragSourceArray = {fragShaderSource};
   int[] strLength = {fragShaderSource.length()};
}catch(Exception e){System.out.println(e);}

I am not certain if I am doing the glShaderSource method correctly.

In my display(GLAutoDrawable) method, I have these lines which successfully draws a red quad in the center of my canvas.  I figured that the line "gl.glUseProgram(shaderProgram);" would apply the fragment shader and make all the pixels blue, but it seems to have no effect:

And finally my shader code which is in a text file called "fragShader.glsl".  I have not spent any time learning the actual glsl since I first have to figure out how to get a shader running in the first place.  I took this code from the 3D lighthouse tutorial (it said it colors pixels a blue shade):
void main()
   gl_FragColor = vec4(0.4,0.4,0.8,1.0);

I don't know if there should be more to this or not.  Based on what I read, it seems to imply this these lines are all there is.

Perhaps someone can point out my error(s). Thanks
6  Java Game APIs & Engines / JOGL Development / Re: how does one use normal maps? on: 2008-06-30 12:43:20
Well, I have a set of both a vertex and fragment shader.  At this point, I just want to see how to actually get anything running even if it is the wrong thing.  Since I'm not in the computer science field, I would have trouble justifying the purchase of the orange book.  Are there resources online for using jogl and shaders?
7  Java Game APIs & Engines / JOGL Development / Re: how does one use normal maps? on: 2008-06-29 23:16:38
Having no experience in shaders, I would probably have to start with the basics first before I could move on to what I want to do.  I have found a standard snippet of a vertex shader that supposedly is for doing bump maps.  I am now trying to figure out how to have it interface with my jogl code.  If anyone could point me to a source on how that is done, I would be most appreciative.  In the meantime, I'll just keep searching on the internet.
8  Java Game APIs & Engines / JOGL Development / how does one use normal maps? on: 2008-06-29 22:58:49
I have been searching the internet this weekend looking for information on using normal maps, but I am not having much luck on finding what I want.  Mostly everything I came across is either in C, about making normal maps in image editing programs, or isn't the effect I am looking for (i.e. bump maps in NeHe tutorial #22).  I would like to be able to give things a rich textured look like this person had done in his first screen shot:  I already have a regular texture and a normal map in dds format.  I guess my question overall is how does one do normal maps in jogl?

9  Game Development / Newbie & Debugging Questions / Re: "fog of war" algorithm on: 2008-02-23 02:11:12
The number of units (n) is really up to the end user.  I really can't conceive of n ever being less than 100 or more than a million.  It depends on how complex the simulation needs to be.  I would guess the "average" user would opt for around 1,000 to 10,000 units.  An important point is that I am planning to have some units grouped together moving as one "super-unit" which would reduce the burden of the fog of war calculation.  If I had to guess, I would say that in the limit as n goes to infinity I could probably expect a 10 fold drop in the number of units I have to run calculations on.  It is possible that I may not have performance issues, but I would like to have a fairly efficient algorithm to start with.

I don't need cube partitions since all the units are positioned on the surface of a sphere.  Would it be best to divide up the units into lists representing portions of the earth's surface area?  It is easy to divide up the sphere surface into rectangles (like this: , but it might be best to just lump all of the polar regions into two lists because the rectangles get small at the poles and there will probably be little activity there.  For a unit in a given rectangle, I would then see if any units in the adjacent rectangles can see it.  I'm new to this, so perhaps you can think of a more efficient way to divide up the units.
10  Game Development / Newbie & Debugging Questions / Re: "fog of war" algorithm on: 2008-02-23 00:40:19
I had thought about using a technique like that to reduce making comparisons of units on opposite sides of the world, but I was concerned about how far the "line of sight" could be for some of the units.  The users of the simulation will decide the parameters of the units (such as line of sight radius) and if possible I wouldn't want there to be a maximum light of sight range just for flexibility's sake.  The performance benefits would probably be worth it though so maybe I will implement it in the end.  Thanks for the suggestion.

Are there other improvements that anyone can think of?
11  Game Development / Newbie & Debugging Questions / "fog of war" algorithm on: 2008-02-22 19:36:50
I have a simulation of shipping traffic around the world, which is displayed on a 3d globe via java opengl (my question has nothing to do with java opengl though).  I would like to be able to evaluate which units can be "seen" by another team of units.  The end effect is pretty much a fog of war.  The unit's positions are stored in spherical coordinates and I will probably just assess distances between units to determine if one can see the other.  If a unit not owned by the user is seen by a unit "owned" by the user, this non-user unit  will be rendered on the globe (along with all the user's units).  The problem is I would like there to be many units and for the evaluations to be carried out quite often.  I have asked this question on another site and the only advice I got was to not model that many objects, which isn't helpful.  What I really want to know is what is the best way to make these evaluations given that I have a very large number of units that can be detected and units that are capable of detecting.

I am currently planning to take a list of all non-user units and iteratively consider whether or not each one can be seen.  This involves taking one of the non-user units and then iterating through the user's units to evaluate if one of them sees it.  If none of the user units see it, the non-user unit is not flagged for rendering and I move on to evaluating the next non-user unit.  If a user unit did see that non-user unit, I stop the evaluation, flag the unit, and move on to evaluating the next non-user unit.

I would appreciate any advice on how to make this better.  Perhaps some heuristic tricks could be of use here.
12  Java Game APIs & Engines / JOGL Development / Re: antialiasing question on: 2008-02-17 04:13:05
Even if it is possible to make your own glcanvas widget, I don't think I am familiar enough with this stuff to figure out what needs to be changed.  I guess this is a roadblock to what I wanted to do and I'll probably have to make do using the embedded awt frame.  Is anyone capable of confirming that  full-scene multisample antialiasing can only be setup in jogl through the GLCapabilities class?
13  Java Game APIs & Engines / JOGL Development / Re: antialiasing question on: 2008-02-15 05:58:09
Yeah I recently came across that too.  I have embedded an AWT frame in my SWT application and antialiasing works this way, but the performance is a lot worse than using an all-SWT approach with antialiasing forced from a control panel.  I don't know whether this originates from the awt frame or from the fact that I had to switch my mouse event listeners from an swt version to one in "java.awt.event.MouseAdapter"

Is there a way to create sample buffers and set the number of samples in a manner that does not involve the GLCapabilities and GLCanvas classes?  In theory, such a method would be accessible to me without introducing an embedded AWT frame.  I see a lot of methods in the GL javadoc page suggestive of being able to generate buffers, but I have no clue if they are relevant or how to use them.
14  Java Game APIs & Engines / JOGL Development / Re: antialiasing question on: 2008-02-04 17:50:50
There isn't a boolean for sample buffers, just an int which I have tried setting to 1 and 2 but with no success.  The link I put in one of my previous posts
( is the javadoc page for the GLData class.  It has only 14 variables that I can set, and the only ones that I think would be relevant are samples and sampleBuffers.

I went through the open bug reports for SWT and found something about multisampling in embedded opengl.  It was reported a couple years ago when an older version was out.  It was marked as a feature enhancement request rather than as a genuine bug.  I have no idea what the current situation with SWT-jogl and multisampling is though.
15  Java Game APIs & Engines / JOGL Development / Re: antialiasing question on: 2008-02-04 07:16:34
I've tried 1 sample buffer for a long time until Ihkbob suggested "You have to set the number of sample of buffers to 2, 4, 8, or 16 (although older cards might not be able to hold more than 2 or 4)."  I'll go back and try to see if I skipped any sample buffer / sample combinations.

I know at least that any combination with sample buffers set to 1 or 2 and samples set to 2, 4, 8, 16 does not produce antialiasing for me.
16  Java Game APIs & Engines / JOGL Development / Re: antialiasing question on: 2008-02-04 06:56:34
This is what I am doing now:

GLData glData = new GLData();
glData.doubleBuffer = true;
glData.sampleBuffers = 2;
glData.samples = 8;

The glData object (the equivalent of GLCapabilities) is then placed in the contructor of my SWT GLCanvas.  Later on in the program I try to enable GL_MULTISAMPLE, but no antialiasing occurs.  I use gl.glGetIntegerv(GL.GL_SAMPLE_BUFFERS,buf, 0); and gl.glGetIntegerv(GL.GL_SAMPLES,s,0); to query the buffers and samples I am using and it returns 0 in both cases.  If I were to "force" antialiasing through a control panel outside my application, antialiasing does work.  I have an nvidia 8400 so the problem shouldn't be my hardware.  It seems like the samble buffer and samples values that I am setting in glData are not making it through.
17  Java Game APIs & Engines / JOGL Development / Re: antialiasing question on: 2008-02-04 06:22:02
That's a possibility.  I don't set anything other than double buffering, the number of sample buffers, and the number of samples via the GLCapabilities equivalent.  If you want to take a look, this is what I am using:

I create this GLData object, set its variables, then throw it into the constructor of the SWT-version GLCanvas.  After that nothing else is SWT-specific.
18  Java Game APIs & Engines / JOGL Development / Re: antialiasing question on: 2008-02-04 03:49:41
I went back and successfully ran the nehe example with GL_MULTISAMPLE, but I still can't figure out why nothing happens placing that in my code.  I printed out the number of samples and sample buffers, and to my surprise they were both 0 even though in theory I was setting them to other values.
19  Java Game APIs & Engines / JOGL Development / Re: antialiasing question on: 2008-02-04 03:40:50
I can set the samplebuffers variable to any number I want in the SWT-version of GLCapabilities (I don't know if this has a real effect or not).  I tried values between 1 and 16 and nothing seemed to change anything.

In my third post I said that I was able to get antialiasing to work, but it caused rather visible lines to appear where polygons touched (they were forming a giant sphere).  Is this a dead-end or can I do something to remove the artifacts?  I'm not sure what to do about the edge flags because I create the object in a display list.

The only two methods I have seen for AA in jogl are using this:
(which leads to those lines on the polygons in the mesh)

and using the accum buffer (which I assume is not practical for AA in real-time).  Are these the only two ways to do AA with jogl?  I'm a little confused if enabling GL_MULTISAMPLE constitutes a separate method or not.
20  Java Game APIs & Engines / JOGL Development / Re: antialiasing question on: 2008-02-03 19:49:32
Well I don't have to worry about anisotropic filtering...I already have that working.  I have already seen that nehe example you posted, but I wasn't able to get it to work. Simply enabling GL_MULTISAMPLE doesn't do anything.

Does anyone know how to do antialiasing using these: EXT_framebuffer_multisample or ARB_multisample?  I can't compile my code with these in it.  I don't know what to import if that even is how to resolve that.
21  Java Game APIs & Engines / JOGL Development / Re: antialiasing question on: 2008-02-03 08:10:21
I got the GL_POLYGON_SMOOTH to work now, and I think I am running into the problem that you predicted.  Visually I am seeing lines on the edges of the polygons that compose the large object that I am rendering.  It is problematic since the object has a texture on it.

Are these the only two techniques to do antialiasing in opengl (the polygon smooth and the accum buffer)?  It seems like the polygon smooth technique is not useful if it results in these visual artifacts and the depth buffer can't be used.  Everywhere I read online, I encounter warnings that using the accumulation buffer for this purpose isn't practical for real-time rendering.

Is there a more official way to do antialiasing?  And what is this used for: gl.glEnable(GL.GL_MULTISAMPLE); ... it doesn't seem to do anything when I used it.
22  Java Game APIs & Engines / JOGL Development / Re: antialiasing question on: 2008-02-01 22:23:21
Wouldn't smoothing the edges of the polygons be exactly what I am looking for?  I've read about using the accumulation buffer in the red book before, but I got the impression that this would introduce a slight blur everywhere on the screen, not just the edges of the polygon.  Plus, I am not really going to be running my program on the most powerful machines.

Specifically regarding GL_POLYGON_SMOOTH, how do I make this work?  Merely using glEnable and glHint for this does not "turn on" antialiasing.
23  Java Game APIs & Engines / JOGL Development / antialiasing question on: 2008-02-01 09:53:12
I would like to add antialiasing to a jogl program I made.  I have a large polygon with many tiny polygons on it.  The tiny polygons rarely appear correctly without antialiasing and there are lots of jagged edges where the large polygon touches the background color in my scene.

What is the best way to implement this given my situation?

I am embedding the opengl stuff in an SWT window.  If I understand, this means I cannot use code like this because I don't use a standard GLCanvas:
GLCapabilities cap = new GLCapabilities();

SWT has an object similar to GLCapabilities called GLData which is passed to the SWT version of GLCanvas.  It has two variables sampleBuffers and samples which I have set to 1 and 16, respectively.  I really don't know how to proceed beyond this (or even if what I did was useful).  I have seen reference to using gl.glEnable(GL.GL_POLYGON_SMOOTH) in many places online, but whatever snippets of code I try, they never seem to work.  I feel I am missing something or have something present that is interfering.  Antialiasing does work on my computer as I can enable it by overriding the application via my nvidia control panel.
24  Java Game APIs & Engines / JOGL Development / Re: Texture Coordinates and GluSphere on: 2008-01-21 20:50:33
It should be easy to try, but I don't know if I will do it right.  I really am not sure how the texture that I was using was automatically mapped onto the sphere.  Do you know how exactly the opengl does automatic texture mapping of a glusphere?

The glusphere was made of squares which are of varying sizes (smaller as you get toward the poles).  Does each "square" on the sphere get an equally sized square from the texture image?  Or do the squares near the poles have squares from the texture image with slightly smaller dimensions?
25  Java Game APIs & Engines / JOGL Development / Re: Texture Coordinates and GluSphere on: 2008-01-21 12:45:49
I confirmed that it is hitting the texture size limit with your code (mine only goes to 8192 and I was tried to use a texture with a 16384 length).

Regarding the main question in my previous post, do you have any recommendations on how I can build and texture the two halves of the sphere separately?  I suppose I could try building it vertex by vertex manually, but I would like to know if an easier method exists or not.

26  Java Game APIs & Engines / JOGL Development / Texture Coordinates and GluSphere on: 2008-01-21 02:55:06
I would like to apply a massive texture on a sphere (16384x8192), but I believe this doesn't work at these sizes.  I am using a standard File object and creating TextureData with it which I then set the internal format of the data to compressed DXT1 (supposedly this should decrease the memory required for the texture by 8x).  I then create a Texture object with this TextureData.  The thing I apply this texture to is a glusphere.  I automatically generate the texture coordinates with the glu method "gluQuadricTexture".

This works fine when I had a single 8912x4096 image that I used as a texture, but using the larger image means the texture doesn't appear on the screen.  What approach could I take to place this larger image on that sphere?

I was thinking of cutting the image up it into 4 pieces as putting those individually on the sphere.  If the compression of the TextureData works as it is supposed to, the total memory requirement for the 16384x8192 is 64MB I think.  Is there any way to do this without actually creating the sphere vertices and texture coordinates manually one at a time?
27  Java Game APIs & Engines / JOGL Development / Re: Texture Compression of very large images on: 2008-01-18 09:30:42
Thank to some help I found at the forums I was able to solve my problem.  For the reference of anyone reading this thread I will post what I did below.  If you think there is a better way to do this, please tell me too.

When creating a texture, the lines of code I used was as follows:
TextureData textureData = TextureIO.newTextureData(new File("Image.png"), true, null);
texture = TextureIO.newTexture(textureData);

(this requires importing at least the following: com.sun.opengl.util.texture.Texture, com.sun.opengl.util.texture.TextureData, com.sun.opengl.util.texture.TextureIO, and

This was done in a try-catch statement, and "texture" refers to a Texture object whose declaration is not shown.  Apparently this call applies a compression algorithm called DXT3 on the textureData.  I don't know if this is the best argument to use in the setInternalFormat method, but it does work.  I can now switch between my formerly uncompressed 8192x4096 textures smoothly and I really can't detect any visual degradation due to the compression.  The time it takes to initialize the program has increased a lot though supposedly due to the time spent compressing.
28  Java Game APIs & Engines / JOGL Development / Texture Compression of very large images on: 2008-01-18 02:31:56
I am trying to get texture compression into my jogl program in which I have a sphere that I would like to use 2 different textures on at different times.  These textures are large 8192x4096 images in .pgn format.  If I want to switch which texture is being useful when rendering it takes at least 6 seconds on my mid-range 6 month hardware.  This is not responsive enough.

Right now I use the following lines of code to place a texture on a gluSphere:

//stuff mostly in the constructor (the "glu" is a GLU object), I do this twice for the two textures
GLUquadric quadric = glu.gluNewQuadric();
glu.gluQuadricTexture(quadric, true);  // I believe this tells it to automatically do the texture coordinates and mipmaps
Texture tex = null;
tex = TextureIO.newTexture(new File("image.png"),true);
}catch(Exception e){}

//later on I call this to render the gluSphere

To switch between textures I call tex.bind() or tex2.bind() right before the gluSphere call.

Is this proper technique?  Moreover, would adding texture compression improve the speed at which it can switch between my textures?  Since the textures are so large I am concerned about them not fitting on my video memory simultaneously.  However, I called "getEstimatedMemorySize()" on my textures and they returned 96MB for each texture which is less than the 256MB that I have to work with.  I believe that my code does automatically make mipmaps which could increase the memory load to more than what I have available if I understand how that works.  I noticed that my page file usage (I ran this on windows xp) increases from around 250MB to 1GB when I run my program, which seems to be more than would be possible even if everything were stored there.
Pages: [1]
EgonOlsen (37 views)
2018-06-10 19:43:48

EgonOlsen (20 views)
2018-06-10 19:43:44

EgonOlsen (39 views)
2018-06-10 19:43:20

DesertCoockie (186 views)
2018-05-13 18:23:11

nelsongames (122 views)
2018-04-24 18:15:36

nelsongames (121 views)
2018-04-24 18:14:32

ivj94 (861 views)
2018-03-24 14:47:39

ivj94 (122 views)
2018-03-24 14:46:31

ivj94 (758 views)
2018-03-24 14:43:53

Solater (139 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!