Doh I was aware of that bug ever since I ported the demo, and yet I didn’t fix it on time and then I got sucked into other stuff and completely forgot about it …that’s just lame :-/
But the fix consists in changing those lines position to somewhere else, you are right
Hi, Sean,
Thanks for replying. Where and how did you change GLCapability in JOGL?
wz
To change the capabilities in Jogl…
Assuming you are using the AWT or Swing components provided in Jogl, then you would create a GLCanvas (AWT) or GLJPanel (Swing) using a GLCapabilities object and put these components in a Frame or JFrame. So, to create a GLCanvas, the following code might be used:
GLCapabilities vCapabilities = new GLCapabilities();
GLCanvas vCanvas =
GLDrawableFactory.getFactory().createGLCanvas(vCapabilities);
To request a canvas with different properties, use the methods provided by GLCapabilities and pass it into the createGLCanvas() factory method. Hope this helps.
Sean
Lesson24 NEW!
PS: Char arrays are evil(took me 2 hours to realize what was wrong in my code >:( ), stick with bytes 8)
Lesson18 Fixed minor bug in disable/enable lighting.
Lesson30 NEW!
Alright I spent about 7 hours STRAIGHT working on the linked port to have it finally up and running; damn my eyes are almost bleeding now that I’m done :’(
I have one bug that I couldn’t fix though, and hence the main reason behind posting the whole source this early to get some help.
Basically when I change the size of the frame on runtime an exception occurs and the demo stops.
That same bug prohibits me from accessing the fullscreen mode, any help would be appreciated
Now my other concern is rather a matter of taste and high standards: Java audio playbacknever was my thing as it truly sounds hideous.
My suggestions is to hit F3 immidiately after starting the demo, otherwise don’t blame me for harming your sensitive ears ;D
/me thinks it’s about time he takes a closer look at JOAL
New addition: Multiple sounds played at once, and a lot better playback quality (still not good enough, might work on an mp3 loader and add it later on).
Any suggestions on the resize bug? I wanna move on to my two lasts port, I have a [censored] load of homework sitting on my desk :’(
Any idea when we can expect all the code to appear on the NeHe site?
The ported NeHe tutorials are great, but as Caoimhin already commented, not consistent.
The advantage of consistency between the lessons is that a total newbie can understand what a particular piece of code does. He isn’t confronted by new ways of programming, which is particularly helpful when learning a complete new area. I don’t consider myself to be a newbie in Java programming, but I am one in OpenGL.
I adopted Caoimhin’s way of programming for doing these NeHe tutorials simply because he did the first seven lessons. It has some advantages and disadvantages, which I’m not going to discuss.
Maybe you guys can come up with a different way of presenting these lessons for what it’s worth. It doesn’t really matter, as long as they look the same. And I think that should be your ultimate goal.
I agree that we should use a common base for the tutorials. What I tried to do in my code is to not pollute the ‘lesson code’ with basic jogl setup code (the component, fullscreen stuff, etc). It was an effort to keep the essence of the lessons (the actual OpenGL code) in one place.
What do you guys suggest for a clean common base? If we can agree on a common base or someone provides one, I would be happy to port the code I’ve written.
I would be happy to port them all to the same format too when they are done, I already moved them all to the same package structure and modified them so they work from a jar and command line, and also made it so they work in both linux and windows.
I agree with pepijnve that the jogl code should be seperated out from the other code. I like how he setup his code, allows for easy reading.
nathan
Hi, JOGL gurus,
When I run your NEHE programs, I had a lot of exceptions out ot JVM as I stated in previous posts, for example Lesson 11. Then in Lesson 11 and Lesson 3, I had to create an Animator animator = new Animator(canvas), then use animator.start() to run it. I am using RH linux 7.2 and old hardware. Does anybody knows why??? Why was animator not used in the examples??? Any particular reasons? I want to find out the cause of the problems so that I do not have to change every program.
Actually, after I fixed Lesson 11, it runs better than the C code on my work station. When I run C code, there is not much animation. But when I run jogl, it flys.
Thank you very much.
wz
I’ll modify the code I wrote to use Animator, since this seems to be more compatible. The only real difference between the two is which thread is doing the rendering. In the case of Animator it’s a separate thread. In my code it’s the AWT thread. If this really causes that much problems, it looks to me as a bug in jogl rather than a bug in the code.
Hi,
Thank you very much for letting me know the difference. I agree that the problem may be in jogl since all other parts of the code work well after using animator. Maybe somebody from JOGL developing team can answer the question.
Thanks again.
wz
I’d go for the common work frame, but so far the only difference that my code holds against Nehe’s is just the basic Java set up for a Canvas
public static void main(String []args) {
int fullScreen = JOptionPane.showConfirmDialog( null, "Would you like to run in fullscreen mode?",
"Fullscreen", JOptionPane.YES_NO_OPTION);
frame = new JFrame();
demo = new Lesson30();
screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
switch(fullScreen){
case 0:
frame.setUndecorated(true);
break;
default:
canvasWidth = 640;
canvasHeight = 480;
xLocation = (screenWidth - canvasWidth )>>1;
yLocation = (screenHeight - canvasHeight)>>1;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(xLocation,yLocation);
}
frame.getContentPane().add(demo.getCanvas(canvasWidth, canvasHeight),
BorderLayout.CENTER);
frame.pack();
frame.requestFocus();
frame.setVisible(true);
if(fullScreen==0){
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().setFullScreenWindow(frame);
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().setDisplayMode((new DisplayMode(640, 480, 32, 60)));
}
}
GLCanvas getCanvas(int w,int h){
canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
canvas.setSize(new Dimension(w,h));
canvas.addGLEventListener((renderer = new initRenderer(demo)));
frame.addKeyListener(this);
canvas.addKeyListener(this);
return canvas;
}
I also include an extra class for the animation
import net.java.games.jogl.*;
public class initRenderer implements GLEventListener
{
GL gl;
GLU glu;
Lesson30 main;
GLDrawable glDrawable;
initRenderer(Lesson30 main){
this.main = main;
}
public void init(GLDrawable drawable){
this.gl = drawable.getGL();
this.glu = drawable.getGLU();
this.glDrawable = drawable;
main.gl = gl;
main.glu = glu;
main.initialize();
drawable.setGL( new DebugGL(drawable.getGL()));
}
public void display(GLDrawable drawable){
main.display();
}
public void reshape(GLDrawable drawable,
int xstart,
int ystart,
int width,
int height){
height = (height == 0) ? 1 : height;
gl.glViewport(0,0,width,height); // Reset The Current Viewport
gl.glMatrixMode(gl.GL_PROJECTION); // Select The Projection Matrix
gl.glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
glu.gluPerspective(50.0f,(float)width/height,10.f,1700.0f);
gl.glMatrixMode(gl.GL_MODELVIEW); // Select The Modelview Matrix
gl.glLoadIdentity();
}
public void displayChanged(GLDrawable drawable,
boolean modeChanged,
boolean deviceChanged){}
}
If a common frame has to be set, I would like to see fullscreen implementation in it, actually I can take care of that part if no one sees harm.
I reworked my code a bit and here is the end result http://pepijn.fab4.be/nehe/nehe-demos.zip. These are all the lessons I ported in one big zip. They now use a modified Animator class that has some very basic frame rate control. I also integrated the fullscreen stuff from JavaCoolDudes ports.
w0zhang: does this version work better?
I won’t be touching anything for the next week or two. I’ve a dev deadline at work. :-/
Hi, Pepijnve,
Thanks a lot. There is one small glitch. You used Animator(canvas, 60), but I could not find such constructor for Animator in my JOGL lib. I think I am using the Sept. 5 release. After I changed it to Animator(canvas), it worked great. I tried lesson 11 and 14. It is great that you put commonlly used file in one folder.
I used C OpenGL before. It seems that this java stuff is much less portable than C!!!
Thanks again. I had problem with every NEHE demo and was not targeting you.
wz
I had modified Animator to have this extra constructor. The extra integer is a desired frame rate. This modified version of Animator was also included in the zip file. To make things clearer, I’ve renamed my modified Animator to FPSAnimator (should have done this in the first place). It still has to be in the net.java.games.jogl package since Animator uses some package visible methods of GLCanvas.
The file at the previous URL contains the updated version.
pepijnve,
I have jogl installed as an extension to my 1.4.2 JRE and am getting an IllegalAccessException with FPSAnimator. Since there is only one line that needs to access package visible methods and it is in the Animator constructor, we can have FPSAnimator extend Animator without having to play tricks with packaging. Like so:
package demos.nehe.common;
…
public class FPSAnimator extends Animator {
…
/** Creates a new Animator for a particular drawable. */
public FPSAnimator(GLDrawable drawable, int fps) {
super(drawable);
this.drawable = drawable;
this.delay = 1000 / fps;
}
…
Everything else is the same. Also please include your build script in the .zip.
Thanks for your work.``
Ok thanks for the advice. I’ve applied the change and updated the zip file on my server. I hadn’t realized that only GLCanvas.willSetRenderingThread is package visible and the other methods related to the rendering thread are public.
Right now I don’t have a build script yet ;D I just let my IDE do all the work. I’ll write a little ant script tonight if I find some time.