Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Java 3D / April 2004

Tip: Looking for answers? Try searching our database.

Problems writing view-independend text into Canvas3D

Thread view: 
Roman Vottner - 10 Apr 2004 21:25 GMT
hi there,

first of all i am quite new to java3d as i got involved in a
university-project which should meassure the performance of java3d and
provide a networkgame. in concrete the game should provide a platform where
users can walk on. the platform itself should rotate on the center of the
platform depending on the center of gravity. The server-application
receives the view-direction (vector3f) and the speed of the user an
calculates the exact position of the users as well as the rotation of the
platform which is sent as a result to the users to modify their view.

so far i have written an application-framework which provides independence
of the used output-device (windowed-jframe, fullscreen-jframe and applet)
which uses an Application-Factory based on the introductory chapter of
Norman Lin's "Linux 3D-Gameprogramming". The network-code has been
implemented in the last 2 to 3 days, which is based on chapter 6 of
"Developing Games in Java" (co-author Bret Barker wrote this chapter) too.
and i am able to exchange messages.

having managed this so far i implementet a FrameCounter-Behavior which is
very simple. just count the frames got from the view object (framenumber)
and reduces it by the old framenumber. this happens every second to get a
FramePerSecond-Counter as you can imagine. so far I have written the output
to the console but this is imho not nice.

to come to my problem: i am currently writing the text (text2D) into the
canvas. but as i change the position of the view the text-object gets
changed too even thoug i place the text-object in a seperate branch-group
of the viewGraph. my second attempt is to fetch the graphics2d-device from
the canvas i use and to draw the text ant paint the graphics-device with
the canvas3d paint()-method. no error but no seeable output too. this leads
to my next try. i create a text3d-object as follows:

Font3D font = new Font3D(new
java.awt.Font("Serif",12,java.awt.Font.PLAIN),new FontExtrusion());
Text3D text = new Text3D(font,s,new Point3f( 0.5f, 0.5f, 5.0f));
Shape3D sh = new Shape3D();
Appearance app = new Appearance();
Material m = new Material();
m.setLightingEnable(true);
app.setMaterial(m);
sh.setGeometry(text);
sh.setAppearance(app);
Transform3D t = new Transform3D();
t.setTranslation(new Vector3f(-0.1f,-0.1f,0.1f));
m_ctx.setModelTransform(t);
m_ctx.draw(text);
m_ctx.flush(true);

where m_ctx is a reference to a GraphicsContext3D-Object and s ist just a
holder for any string. But this leads to the following exception (if run in
postRenerer() the exception markes Exception occured during Canvas3D
callback instead of Behavior execution)
Exception occurred during Behavior execution:
java.lang.IllegalArgumentException: TriangleArray: illegal vertexCount

but i used the creation of the text3d out of an example wo i am a little
wirred of what goes wrong?!

next approche: using the  graphics-object (not the graphics2D!!!) which is
returned by canvas3D and define the following in the postRenderer() of an
extended version of canvas3d

java.awt.Graphics g = this.getGraphics();
g.drawString(s,10,10);

this works but the text blinks and is therefore not well suited. drawString
of graphics2D-object don't work for me and i don't know why (neither on
linux nor on windows)

2 more solutions:
1: Create a Text2D Object and show it using the GraphicsContext3D-Objects'
methode draw() (again in postRenderer() of derived Canvas3D-Class). This
shows text but this text moves with the scene if i change the view (the
branch the view is in). after a time i receive an
java.lang.OutOfMemoryError as new Objects seem not be garbage collected

Transform3D t = new Transform3D();
t.setTranslation(new Vector3f(-0.6f,0.4f,0.0f));
Text2D m_text = new Text2D(s, new Color3f(0f, 1f, 0f),"Serif", 10,
java.awt.Font.PLAIN);
m_text.setString(s);
m_ctx.setModelTransform(t);
m_ctx.draw(m_text);

if i define m_text outside of postRenderer() i don't even see the text

2: last one again in postRenderer()

// private Classfields
private java.awt.geom.AffineTransform t = null;
private java.awt.Font m_font = new
java.awt.Font("Serif",50,java.awt.Font.BOLD);

// in postRenderer()
J3DGraphics2D graphics = this.getGraphics2D();
t = graphics.getTransform();
t.setToScale(12,12);
graphics.setTransform(t);
graphics.setColor(java.awt.Color.green);
graphics.setFont(m_font);
graphics.drawString(s, 0, 1);
graphics.flush(true);

this methode works. i can move the view an the text stays on position. but
this works just for static text as the old text, which has been drawn the
frames before, dosn't get cleared and so the text overrides itself (which
for static purposes isn't bad). another thing to mention here is that
framerate drops by more than half. if i print the framerate to console i
get on a athlon xp 2200+, 512 ddr, nvidia gforce 4400 ti, mandrake linux
10, xfree 4.3 ~500-800 frames/sec. with this methode i get just ~280 fps.

so has anybody an idea of how to deal with this? any help is appriciated. i
would be glad if you can send code too :)

lg,
roman
Roman Vottner - 10 Apr 2004 22:02 GMT
> 2: last one again in postRenderer()
>
[quoted text clipped - 20 lines]
> get on a athlon xp 2200+, 512 ddr, nvidia gforce 4400 ti, mandrake linux
> 10, xfree 4.3 ~500-800 frames/sec. with this methode i get just ~280 fps.

well ... i guess i should have used the time for testing and experimenting
than of writing those message obove as i have found a working solution for
me. it is almost the same as above but fewer lines of code. I put the
declaration of graphics in the construktor and left away the other parts
except the following in postRenderer():

graphics.drawString(s, m_cntX, m_cntY);
graphics.flush(true);

now the text gots updated corectly :) and the framerate is up to 500-600. it
seems that the transformation (scaling) and the grab of the graphics-object
cost ~100-200 fps

but if you have any other suggestions feel free to write :)

lg,
roman
Roman Vottner - 13 Apr 2004 21:56 GMT
hi,

> I put the
> declaration of graphics in the construktor and left away the other parts
[quoted text clipped - 6 lines]
> it seems that the transformation (scaling) and the grab of the
> graphics-object cost ~100-200 fps

it seems there are big differences between the windows version (ogl) of
java3d and the implementation of blackdown java3d for linux. i've testet
the code written in linux on windows with 2 different execution behaviors.
on my laptop (which only has a shared graphics-chip) the application throws
a jni-Exception and creates a logfile in the project directory (so this is
out of my thing i guess). the second machine is my linux box where i have
windows installed too. the code runs without problems but i just get a
framerate of 102 frames on a 640x480x16 resolution at maximum

is the linux version of blackdown realy so optimized, or the windwos
ogl-version so slow? why are there differences of 400 to 500 frames per
second with the same code? or does the windows-version support page
flipping automatically? i just thougt of double buffering. or does double
buffering wait for the refresh signal of the monitor too, which leads to a
maximisation of fps to the monitors' refresh rate set by the user? if it
depends on the refresh rate how should i code to get the real possible
frame rate than via a self-written behavior which wakes up on expired time
of 1000ms (1sec). and does the call of J3DGraphics.drawString() realy need
a 3D-Support on graphic-devices (jni-exception on my laptop)?

last question. why dows java3D ignore declaration and settings of graphics
made in the constructor? in exact i tried to define the font, fontsize and
textcolor in the constructor as java3d seems to ignore new instantiated
objects to be garbage collected (-> outofmemory-exception when defining new
objects (font,color,...) after a time in the postRenderer()-methode)

any one has made experiences on that?

lg,
roman


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.