Advertisement

[java] Fast graphics in java, possibly .....

Started by September 01, 2000 10:13 PM
7 comments, last by loserkid 24 years, 3 months ago
Ok, lately I''ve been working on writing my own 3D Engine (without Java3D or any other 3D API) and looking for fast ways to draw stuff to the screen ... so I''ve been optimzing my code like a madman and I''ve increased performance about 30%. So I think great! i''ve got a sphere rotating wildly on the screen being shaded by a light source. Then i put a torus in my engine and I get a nice slow down - "more faces, more calculations" I say, so it''s going to be a bit slower ... so then I go to one of my fave Java sites Sumea and look at there cool 3D stuff and say to my self "damn". They had a pair of evmapped sun glasses rotating nicely on the screen.(more polys than my torus ) So then I think their must be a way to draw stuff faster to the screen ... So I searched for other Java 3D engines and came upon Peter Walser''s Site and he had his own EXTREMELY stunning 3D engine with all the bells, and everything was running soooo fast. Much to my surprise he had the source to his engine so I took a quick look at it and his engine made NO calls to any of the Java graphics methods except drawImage(). Then i looked closer and he uses just an array of ints representing the pixels of the image and the ImageProducer class to update the image (*without createImage()*). Then *smack* I hit my head and wonder is that really faster? Because each time you want to access a pixel to draw stuff or change the color you have to y*width+x which is another multiplication to add to all the other complex calculations. (of course this method is faster for texture mapping). If you''re still with me, here is the question: If you have used Peter Walser''s method for drawing stuff to the screen, by how much did this increase the performance of your program and why is java graphics so much slower? ============================= silly programmer vb is for kids. ============================ www.thejpsystem.com
==============================================I feel like a kid in some kind of store... ============================================== www.thejpsystem.com
What do you mean by "why is java graphics so [slow]"?

Everyone knows that java graphics are slower than equivalent c/c++ counterparts. How were you painting stuff to the screen before? Just called each objects paint method? Of course that''s going to be slower just from the sheer number of function calls. Painting everything into an array of on ImageProducer is kind of akin to video memory. You just write pixels into the array, and they get painted to the screen whenever they can. I only do this trick when i''m doing 2D effects like alpha blending or rotation.
Advertisement
Damn, I feel dumb for asking that question... Of course the function calls would slow it down a bit when compared to access the pixels directly ().

Thanks for your comments.

=============================
silly programmer vb is for kids.
============================
www.thejpsystem.com

Edited by - loserkid on September 2, 2000 2:11:53 PM
==============================================I feel like a kid in some kind of store... ============================================== www.thejpsystem.com
Why bother when OpenGL exists, is almost as portable as java, and is available from java using a variety of libraries?



Well OGL is cool and all, but I''m making my 3D engine as a Learing experience ... plus I may, in the future want to make some sort of "game" that will be played in the browsers... so if I use OGL the people who might want to play my game have to download the OGL library to their browsers java libraries ... Of course people will have to download my 3D engine class files, but I don''t think I will have a full blown API like OGL. If I were to use OGL for a game, it wouldn''t be in java, I would do it in c++ ().

Thanks for your comments.

=============================
silly programmer vb is for kids.
=============================
www.thejpsystem.com
==============================================I feel like a kid in some kind of store... ============================================== www.thejpsystem.com
quote: Original post by StratMan

Why bother when OpenGL exists, is almost as portable as java, and is available from java using a variety of libraries?



OGL exists for Java? That''s news to me. The last time I checked there were only two libraries that claimed to be OGL Java libs. They were horrible though, and cost money. OGL is very non-OO, it doesn''t fit well with java at all. Plus installing java libs that have native code is difficult. loserkid, check out www.cfxweb.net There is supposedly a java demo/effects message board where you can ask these sorts of Java questions.
Advertisement
Check the OpenGL section of the FAQ. There are links to some good introduction articles for using OpenGL in Java.

http://games.cpbinc.com/faq/ogl.asp

There are 5 or 6 links from the page to various Java OpenGL API''s - I believe a few of them are open source. The only library I am familiar with in detail is Magician (it is what I am using to build my engine). Arcana has done a pretty good job of wrapping OpenGL''s procedural nature into an object-based structure. It''s performance is fairly good as well.

,JL

I''m a newbie and all (not an excuse!),
but judging by what you said Jim_Ross, you can update the onscreen graphics without calling paint()???
you just update the graphics in another method using image producer?

What is the ideal way to update graphics then?

Cause i was reading in a book
and I don''t understand how to draw to the right graphics object unless it''s in the paint method?
no,no, you still have to call paint, it''s just that you are only painting the Image made from the ImageProducer, and not a whole bunch of sprites / 3D objects.

This topic is closed to new replies.

Advertisement