[Loading A 'small movie' in .PNG frames (Memory DEBO)] *closed*... (._.)

(Too bad spoilers don’t work here T_T)

That is why my game has a ‘Theme’…
Cheap and inconsistent?, this is a 2 day old project O.O, only ‘Sprites’ implemented so far are in the main menu (Just the Animated Background), everything else I.E the Menu / Buttons are Round Rectangles for now.

lolz mate, 100FPS steady, no lag spikes, 1,500+ projectiles.
Only problem at the moment is the memory issue with these frames, I’ll take Sprite/Menu criticism later when I decide to post this in WIP for some feedback. :wink:

On a serious note:
Thanks for all the feedback so far guys :slight_smile:

At the risk of putting too fine a point on it, that’s basically writing your own video codec. It might be reliable if you get it right, but unless you’ve got a lot of experience in signal processing, you’re not going to get it right the first time, or even the several dozenth.

This is an area where flash just dumps all over java. Maybe try javafx instead?

Exactly. And because the OP doesn’t want to do streaming, this is the only other way to reduce RAM usage without losing data.

For programming in general:

If something doesn’t work no matter how you code it, cheat. 99.9999% of your users won’t know what you did, so who cares? And if all else fails, cut it out of the project.

If you struggle with that, try finishing the next Ludum Dare. It’s good practice.

@OP: You will need to change something about your original plan if this is going to work. You can’t make a wheel from water (unless you use ice, but that will melt unless you live in a cold place)

Well thanks all of you guys, for nudging me to bump my standards up a bit lol.

Been programming LWJGL for the past 30 minutes or so, apparently I need a Fragment Shader just to have .PNG textures visible on a Quad?

T_T lol guys, if I hop to LWJGL and completely drop Java2D projects, expect to see the Newbie Questions / OpenGL Questions hit up big time D:

*Spam clicks close button on IDE*
*Re-opens*

You don’t need a fragment shader for a textures. Use glTexture2D() and supply texture coordinates in some way. (Depends on your rendering method)
(Make sure you call glEnable(GL_TEXTURE_2D) before or it won’t work)

Have a look at these resources: (you will have to Google them)

Coke and Code tutorials
Lwjgl wiki

And davedes has some good tutorials on 2D lwjgl rendering. I think the link is in his signature.

If it seems a bit hard, try just using immediate mode. You can always learn the better practices (like VBOs) later.

Also, use triangles, not quads. Quads aren’t always supported on graphics cards.

Gasp ok.
Triangles you say, thanks for the feedback GraveDev.


glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture.getTextureID());

Thank you for that :cranky:, now it’s working ;D

I removed LWJGL’s custom ‘TexturedVertex’ class that I was attempting to use, downloaded Slick + PNGDecoder.

Question:
Everytime I draw a quad/triangle etc, do I have to pushMatrix() + popMatrix()?

Lolz, rather happy that it was easy to use a JFrame + Canvas + JTattoo Look And Feel:

You only need to call glEnable(GL_TEXTURE_2D) at the start of the program or if you disable textures and want to enable them again.

Lwjgl (and opengl) are state-based, so whenever you call a function, the data you set will remain that way until you call another function which changes that data.

You only need to push/pop the matrix if you need to store the current matrix for later use. It’s probably good practice to call glLoadIdentity() (which resets the matrix) at the start of each frame to make sure the matrix doesn’t get corrupted. (If you translate the matrix every frame without resetting it you end up with a mess)

The best way to answer your question is to see what happens without pushing/popping the matrix.

You can set nearest neighbor in java2d using rendering hints…it is what I said before. Try reading about the stuff your are using. 1,500+ projectiles is nothing. Using basic glBegin glEnd will yield close to 10x performance depending on the computer.

Switching to opengl will not solve his memory problems unless java2d is bloating everything up a whole lot. Let me just reiterate your options.

  1. Stream an actual video of the animation in which case opengl will help a lot.
  2. Do some hacky way of loading and freeing but I really don’t think it will work much.
  3. Reduce the size by 50% and using rendering hints to increase quality of scaling.
  4. Drop the crazy method of doing this. If you look around I have posted a bajillion menus screen demos which don’t look to bad and are very dynamic. They also do not use more then 1 gig of ram.

Good luck on this and good luck using opengl.

The reason to use OpenGL is so the OP could create a video and play it through one of the lwjgl media players.

Libraries like LibGDX exist so that you don’t need to deal with OpenGL boilerplate.

I’ve been writing my own series that covers various LWJGL and LibGDX topics.

Some articles you might find useful:
Textures - Explains how textures work in detail. This is basically how LibGDX’s Texture class works under the hood.
Sprite Batch - Intro to sprite batchers.
Shaders - a series on GLSL and shaders. More useful for LWJGL devs, or those looking to get extra power/performance out of LibGDX.

The truth is, you don’t need to know any of the “low level” stuff (like glTexImage2D, or GLSL) if you are using LibGDX. It’s a flexible API with a lot of high level utilities; see the following example to get an idea of how easy it is to manipulate textures, play sounds, and handle input:
http://www.java-gaming.org/?action=pastebin&id=358

LibGDX comes with a GUI tool to easily setup projects in Eclipse. There is also tons of documentation on it:
http://libgdx.badlogicgames.com/documentation.html

Keep in mind, even if you do use OpenGL and hardware acceleration (be it LibGDX or LWJGL), you will still have the issue of decoding hundreds of PNG files, and uploading them to the GPU at a steady frame rate. Like we have all been saying, you are going about this the wrong way… :stuck_out_tongue:

P.S. Don’t expect to find a media player in LWJGL that will be easy for a newbie to drag and drop into their project. If you really need media playback, and you are new to OpenGL, you’d have a much easier time using Unity3D or another platform.

Well your background looks great and if something needs improvement its the gui - but its just 2 days old, so come on

basically, video with java2D… no
if you use Libgdx you can use Riven’s YUNPM
or GstLwjgl, which nsigma and I wrote - I use it with Libgdx :smiley:

Actually, both YUNPM and the GStreamer code bring the data into Java before pushing it to OpenGL, therefore there’s nothing stopping you displaying that through Java2D - this is exactly how the software pipeline in Praxis works. This screencast happens to be using Java2D (with a webcam and file feed simultaneously).

m-PhKAQdt28

I still say the OP should bother to Google for “ImageIO MJPEG” before trying with native libraries though - there’s countless examples of image-only MJPEG playing. I used to use that approach with an IP camera (just an infinite MJPEG file!) about 6-7 years ago and it worked much better than what he’s got now.

Praxis is Java2D ?
Either I never knew and assumed it was OpenGL or suppressed my knowledge of that fact ;D

It has a software renderer and an OpenGL renderer, though the software one is primarily custom (direct pixel manipulation) and uses Java2D as little as possible! :wink:

It just so happens that in that particular screencast, the rotation is being done by Java2D and all in software as it can’t use any of Java2D’s accelerated pipelines - it’s pretty smooth - thought it was a good example of not assuming Java2D is that slow! ;D

Incidentally, the reason that example is in software is that Praxis is currently limited to one renderer at a time, and the OpenGL one can only run one window at a time - two are needed for the blob tracking, which is software anyway. It’s a limitation that I’ll be getting rid of shortly.

Lolz, LWJGL / Slick can’t even load 30 consecutive frames without pulling a OutOfMemory error.
Java2D could spit out 123+ frames in a few seconds and update a UI on time.

Now I see why all you were saying ‘That’s not a good idea’.
Seems like no one did what I did in Java2D in LWJGL how I did it. (people who replied)

Java2D FTW? :point:

How I did it in LWJGL:


int i = 0;
LinkedList<Texture> textures = new LinkedList<Texture>();

public void update(int delta) {
	if (i < 123) { /* Only execute once right? */
		textures.add(handler.loadTexture("Frames/Export "+i+".png"));
		i++;
		gameWindow.setProgressValue("add 1");
	}
	/* More update code... */
}

…really? No one said that they would magically make everything work. Also, you may not have been doing everything right so… Good luck with java2d.

Textures are stored in VRAM, and that loader expands textures to powers of two. That means your textures will be stored as 2048x1024 textures, most likely in RGBA format. Wrote your own loader and store them in just RGB. Just be sure to not save the images once you’re done with them.

Wait, did you say a Java out-of-mem-error?

Yep, with LWJG.
I got bored last night, decided to attempt to load my 123 frames, couldn’t get past 30 frames without OutOfMemoryError from Java T_T.

I’ve messed with LWJGL before, know how to construct a basic setup / switch between 2D / 3D drawing on the fly.
My setup’s fine, the only thing I’d assume I’m not doing right is how I’m drawing, pretty sure there’s a more ‘intermediate’ way

to render than:


glBegin(GL_TRIANGLES);
{ /* Etc... */
} glEnd();

EDIT:
http://www.lwjgl.org/wiki/index.php?title=Using_Vertex_Buffer_Objects_(VBO)

http://www.java-gaming.org/topics/loading-a-small-movie-in-png-frames-memory-debo/28454/msg/258901/view.html#msg258901