Changing Focus Problem

Started by Burhan1976, October 15, 2006, 18:01:47

Previous topic - Next topic

Burhan1976

Hi, I hope you're allright, first, I had a user name (New2OpenGl) and I forgot the password (long time) so you me want to remove it.

I'll try to make quick. I have more than a problem that I need to shoot:

I have made a program that launches the default opengl display window (so it's in windowed mode), and a JFrame that holds the controls of the scene, controls in the JFrame is to change the scene, (things like load next scene, slecet another camera... etc).

Problem1: To navigate the scene, user must click and drag inside the GL window, I use Mouse.setGrabbed(t/f) in order to make the mouse dragging without reaching the outside bounds of the screen, and thus have to move inside again. When user releases the button, mouse is visible again to do other tasks.
I noticed that when I click outside the GL window to change the focused window, mouse don't detect that, and still thinking that it's inside the GL window and keeps it focused, it doesn't activate the JFrame, actualy it doesn't select anything on the desktop. Even when I use ALT+TAB to switch to the JFrame, I need more than a click on the 'active' JFrame to realy activate it.
Also, not using Mouse.setGrabbed(true) would help solve this problem, but it makes navigation very annoying.
So I think the problem is in the way I use the setGrabbed method.
Any help regarding this issue? (code for mouse comes at the bottom of this message).

Problem2: One of the controls in the JFrame is to change the scene (i.e. load another scene) and I created an in-between fade effect, simply, it's to change the alpha value of the verteices in the vertex array using a ticker, then reload this array again to the FloatBuffer, this showed to be producing a jerky and slow fading. I solved this by writing to the Accumulation Buffer instead of changing the values in vertex array, but what if in future work I have to change any value in that array? For example, to make a certain object to be flashing with random colors? I tried to make the FloatBuffer to be backed by the vertex array, but I noticed no signeficant improvement.
Any help in using fast update for buffers?

Sorry, I couldn't make it 'quick'. :)

Finally: I use lwjgl beta 0.92. So maybe the solution is simply to upgrade to a higher version.
Now code for the mouse grabbing:

---------------------------------------------------------------------------------
//Called every update to check mouse's status
protected void checkMouse() {
   Mouse.poll();
   int x = Mouse.getDX() * invert;
   int y = Mouse.getDY();

   //Fake mouse events
   if (Mouse.isButtonDown(0)) { //button 1
     if (!Mouse.isGrabbed()) {//Avoid calling the function if mouse is already grabbed
       Mouse.setGrabbed(true);
     }
     if (x != 0 || y != 0) {
       updateCamera(x, y, true);//Update target's position
     }
   }
   else if (Mouse.isButtonDown(1)) { //Button 2
     if (y > 0 || y < 0) {
       fov -= (float) y / 30f;
       if (fov > fovmax) {
         fov = fovmax;
       }
       if (fov < fovmin) {
         fov = fovmin;
       }
       updateZoom()
     }
     if (!Mouse.isGrabbed()) {//Avoid calling the function if mouse is already grabbed
       Mouse.setGrabbed(true);
     }
   }
   else { //No button down
     if (Mouse.isGrabbed()) {//Avoid calling the function if mouse is already ungrabbed
       Mouse.setGrabbed(false);
     }
   }
 }
------------------------------------------------------------------------------------
Thanx in advance :)

Evil-Devil

For problem1 i suggest to use the AWTGLCanvas. So you don't have to deal with 2 windows.

Fool Running

For Problem2, you could use a shader that would change the alpha values of the vertices. That should run pretty fast.

Otherwise, you might be able to make your vertex array not specifiy color values (don't know if that's possible with what you are working with) and specifiy a color before you render the vertex arrays (with an alpha, if needed). But that would require the entire array data to contain the same color (like white).
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Burhan1976

Ok, thanks, But for issue (2), you said that I could use a 'shader', is there any tutorial available? The maximum thing I can do is to assign textures, even without Mipmapping, because I was concentrating on other issues than graphics, you know, physics, dynamics and math study.
Thanx in advance. :)

Fool Running

Try looking at http://www.opengl.org/code/category/C20 for tutorials on shaders.
If you can do the second idea (not specifing color values) it would be a lot easier. :D
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Burhan1976

You know, I can take the color out of the array, because all the vertecies need to be fully illuminated bright and white to see only the color of the texture and nothing more.
So the second approach is good too, but let me guess how to do this with the interleaved array:
-Set the fill color.
-Draw the interleaved array of type, say GL_T2F_V3F (No color here)? Right?

Thanx in Advance, I'll try this one too.

Burhan1976

Thank you guys, the method that sets the color b4 rendering has worked well.

I want to give something back for LWJGL people and anyone who uses it, but for now I have a strict deadline for the next two days.

I'll start with how to implement a physical camera model, that helps in many cases avoid the project/unproject work by designing a picking model for your needs, also that allows to keep track of the view point in a 3D space, and have a powerfull impact on performance. The model would have us also talk about quaternions (as simplefied as possible, because i'm not a math wiz) since many people need to know about it.

If you're interested please tell me, and since this envolves lots of text tell me if there's a dedicated place to post these subjects.

Thanx in Advance. :)

wolf_m

Quote from: "Burhan1976"
I want to give something back for LWJGL people and anyone who uses it, but for now I have a strict deadline for the next two days.
You could still donate via SourceForge ;)
http://sourceforge.net/project/project_donations.php?group_id=58488

Edit: Whoops, you've got your own donations page at http://lwjgl.org/donations.php .. Didn't realize it.