Currently I’m trying to do simple game that uses dynamic textures (I’m trying to remake Notch’s 0x10c, just for lulz and without looking in his code, so I need dynamic textures for DCPU. My game won’t be MMO though, and probably never will be published or published with big concept changes). However, for a project with one cube and only one dynamic texture, performance is really bad (under 1000fps). Probably because I’m doing something wrong. Currently I’m doing it like:
In simpleInitApp:
[java]abc = new Texture2D(128, 128, Image.Format.Depth24);
bi = new BufferedImage(128, 128, BufferedImage.TYPE_INT_RGB);
g2d = bi.createGraphics();
g2d.setBackground(Color.blue);
g2d.clearRect(0, 0, bi.getWidth(), bi.getHeight());
g2d.setColor(Color.red);
g2d.drawLine(30, 80, 30, 80);
abc.setImage(new AWTLoader().load(bi, false));
mat.setTexture(“ColorMap”, abc);
geom.setMaterial(mat);[/java]
In SimpleUpdate:
[java]int x = new Random(System.nanoTime()).nextInt(128);
int y = new Random(System.nanoTime()).nextInt(128);
g2d.drawLine(x, y, x, y);//will put random pixels on the screen
abc.setImage(new AWTLoader().load(bi, false));
mat.setTexture(“ColorMap”, abc);[/java]
So code is pretty basic. But is unefficient. Can you point me to better way of doing dynamic textures that will be more efficient, while maintaining similar features to Graphics2D’s (drawing basic shapes, etc.)?
How ~1000 FPS really bad!?
What, exactly, were you expecting on what kind of hardware!?
shaderz with noise4d. but 1000fps is not really bad, remember that you will go faster from 2000to1000 than from 1000to0
Is there a special reason for creating a seeded random in the update loop? Why not create one on init and just use it in the update loop, for both, x and y…
@ghoust said:
Is there a special reason for creating a seeded random in the update loop? Why not create one on init and just use it in the update loop, for both, x and y..
This.. or just reseed the same object
@sbook said:
This.. or just reseed the same object
why reseed? in this case its not probable that the line is called more than once a millisecond but in any other loop doing this results in long rows of the same "random" number as you always init with the same millisecond seed.
1000 FPS? ugh, ya time for a new video card.
That means I am in really bad shape … My card pulls only 500 fps for black screen
@Momoko_Fan said:
That means I am in really bad shape .. My card pulls only 500 fps for black screen :/
I thought dinosaurs were extinct.
@madjack said:
I thought dinosaurs were extinct.
I bet your GeForce GT 605 will run at even lower fps. Newer != better ;)
@Momoko_Fan said:
I bet your GeForce GT 605 will run at even lower fps. Newer != better ;)
I only have an old GTX 480 that runs a black screen at +5000 fps. I'll need to get a GTX 680 watercooled I'm afraid. 5000 FPS is so pathetic. :cry:
I think my problem is other one here… Yesterday I was tired and didn’t notice this, but when I run this, Textures(M) quickly goes high, up to several thousands. I tried to fight it with desktopAssetManager.clearcache(), but it’s not very effective (texture usage drops to 1000, but it quickly gets up again).
reuse a texture then instead of recreating it. Actually if draw line is all you need, you could just write a method to modify the texture buffer directly, as it wouldnt be that hard.
Ah ya if you reload a new texture it will cause that, I ran into this exact issue a few weeks ago. The shader will have to recompile then. As empire said, reusing the same texture should help.
Yeah, but how to do that? I.e. there is no easy way to write into Texture2D - you can’t use Graphics2d, and it uses different format so I can’t just put pixel on specified x,y without complicated math. Also as I said I’d like to use all capabilities of g2d, which means ellipses and rectangles too. That routine I wrote in update loop was just a test.
Be aware that g2d isn’t available on android so you are limiting your potential platforms if you use it.
Theres an example in the contributions or general help snippets section
Zarch, I don’t want to put it anyway on Android, since it’ll be pretty complex game and tiny phone hardware won’t be able to take it. Normen, will check that out, thanks.
//edit: I’ve found this: http://hub.jmonkeyengine.org/groups/contribution-depot-jme3/snippets/14/ but it offers only basic pixel putting, Could someone write rectangle/ellipse/line and floodfill function, because I can’t do it on my own (no, really)?