forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Keyboard input in OpenGL

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
DanRRight



Joined: 10 Mar 2008
Posts: 1623
Location: South Pole, Antarctica

PostPosted: Tue Nov 02, 2010 9:30 pm    Post subject: Keyboard input in OpenGL Reply with quote

It's so pity not many use OpenGLwith this compiler. There exist lessons for OpenGL in many languages and compilers (made by Jeff Molofee, Jean-Philippe Perois ("DJIP") and others) but not in this one. Life would be much easier with larger users base, less bugs, problems and conflicts. This and Clearwin (potentially even more with Visual Clearwin) would be no doubt the most shiny selling points of this compiler which is like Swiss army knife is self-sufficient for the what most people do in scientific programming.

Well, besides getting the conflict of <windows.ins> with <opengl.ins> when the functions at the bottom of opengl.ins file are used, i struggle right now to make keyboard handling work in OpenGL.

Two test codes are here, we discussed them on page 2 of this post

http://forums.silverfrost.com/viewtopic.php?t=1396&start=15

If we just for example change the line

i=winio@('%^gr[black]&',300,300,gr_func)

with

i=winio@('%^og[double,depth32]&',400,400,gr_func)

both these versions of keyboard handling (via WM_KEYDOWN or getwkey@ ) stop handling keyboard.

How make OpenGL react on keyboard input? I've done it before reacting on arrow keyboard keys by adding sliding controls of Clearwin in OpenGL windows, and that was sufficient, but now i need that beautiful OpenGL screen reacted on alphanumeric input, but it keeps mum
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 468
Location: Sunderland

PostPosted: Wed Nov 03, 2010 2:04 pm    Post subject: Reply with quote

Dan,

I seem to think that I have had a satisfactory response from openGL for key presses, but I was just experimenting. Here are some code fragments:
Code:

         include <clearwin.ins>, nolist
         include <opengl.ins>, nolist

         integer :: i, draw, myreshape, key, specialk, idle, motion,
     &              passivemotion, mouse_press
         external :: draw, myreshape, key, specialk, idle, motion,
     &              passivemotion, mouse_press

...
         call glutInitWindowPosition(1, 1)
         call glutInitWindowSize(iwid, ihgt)
         call glutInitDisplayMode(ior(GLUT_DOUBLE, GLUT_STEREO))
         i = winio@('%ww[no_border]%pv%`og&',0, 0, w1)
...
         call glutSetWindow(w1)
         call glClearColor(0.9,0.9,1.0,1.0)
         call glutDisplayFunc(draw)
         call glutReshapeFunc(myreshape)
         call glutIdleFunc(idle)
         call glutKeyboardFunc(key)
         call glutSpecialFunc(specialk)
         call glutMotionFunc(motion)
         call glutPassiveMotionFunc(passivemotion)
...

      integer function key(k, x, y)
        implicit real*8 (a-h,o-z)
        include <opengl.ins>, nolist

        character :: k
        integer :: x, y
        select case (k)
        case ('z')
          view_rotz = view_rotz + 5.0
        case ('Z')
          view_rotz = view_rotz - 5.0
        case ('1')
          near = ifind_span(x,y,iend)
          if( near .gt. 0)then
            ivert_type(near) = 1
            call generate_model
          endif
        case ('2')
.....
        case default
          return
        end select
        call glutPostRedisplay()
        key = 2
      end function key
....
      integer function specialk(k, x, y)
         implicit real*8 (a-h,o-z)
        include <opengl.ins>, nolist

        integer :: k, x, y
        imodifier_key = glutGetModifiers()
        if(mod(imodifier_key,2) .eq. 1)then
          view_rot_scale = -1
        else
          view_rot_scale = 1
        endif
        if(mod(imodifier_key/4,2) .eq. 1)then
          alt_pressed = 5
        else
          alt_pressed = 1
        endif
        select case (k)
        case (GLUT_KEY_UP)
          if(view_rot_scale .eq. -1)then
            shift_vert = shift_vert + 0.1d0
          else
            view_rotx = view_rotx - 5.0/alt_pressed
          endif
        case (GLUT_KEY_DOWN)
          if(view_rot_scale .eq. -1)then
            shift_vert = shift_vert - 0.1d0
...
        case (GLUT_KEY_F1)
          scale_ortho = scale_ortho * 1.414
        case (GLUT_KEY_F2)
          scale_ortho = scale_ortho / 1.414
        case (GLUT_KEY_F5)
...
        case default
          return
        end select
        call glutPostRedisplay()
        specialk = 2
      end function specialk
...
Back to top
View user's profile Send private message Send e-mail
DanRRight



Joined: 10 Mar 2008
Posts: 1623
Location: South Pole, Antarctica

PostPosted: Wed Nov 03, 2010 3:24 pm    Post subject: Reply with quote

Thanks for help Ian, i'm trying to make working snippet out of this text....so far though unsuccessfully...

A lot of GLUT stuff like GLUTKEYBOARDFUNC is encoded into opengl.ins some commented some uncommented ...it's a bit messy...but nothing freaking works with keyboard so far...

glutKeyboardFunc is pretty powerful function, but things are not very intuitive for just experimenting blindly. It shows also x,y position where key was pressed, not just ascii of the pressed key, but it has to be initialized accordingly. Doc says

"glutKeyboardFunc sets the keyboard callback for the current window. When a user types into the window, each key press generating an ASCII character will generate a keyboard callback. The key callback parameter is the generated ASCII character. The state of modifier keys such as Shift cannot be determined directly; their only effect will be on the returned ASCII data. The x and y callback parameters indicate the mouse location in window relative coordinates when the key was pressed.
When a new window is created, no keyboard callback is initially registered, and ASCII key strokes in the window are ignored. Passing NULL to glutKeyboardFunc disables the generation of keyboard callbacks. During a keyboard callback, glutGetModifiers may be called to determine the state of modifier keys when the keystroke generating the callback occurred.
Also, see glutSpecialFunc for a means to detect non-ASCII key strokes."

so it's a lot of sh#t initially has to be done to get it work. Damn, it's so easy with mouse handling! Just a call to get_opengl_mouse_state@ or
clearwin_string@('CALL_BACK_REASON')
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 1623
Location: South Pole, Antarctica

PostPosted: Fri Nov 05, 2010 9:19 am    Post subject: Reply with quote

More headaches. In the search of keyboard functions working with OpenGL i tried these two-three

reason01=clearwin_string@('BUTTON_PRESS')
reason02=clearwin_string@('KEY_DOWN')
reason01=clearwin_string@('MESSAGE_HOOK')

Got error "Is not known to clearwin_string@". Checked same function with parameter 'CALL_BACK_REASON' it works fine.


Last edited by DanRRight on Fri Nov 05, 2010 3:21 pm; edited 1 time in total
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5007
Location: Salford, UK

PostPosted: Fri Nov 05, 2010 12:37 pm    Post subject: Reply with quote

"BUTTON_PRESS" is a value returned by clearwin_string@("CALLBACK_REASON") and nothing more. It is not an input value to any routine.

These "reasons" only apply to certain controls. You can see what reasons are provided for a given control by printing the results of clearwin_string@("callback_reason") from within your callback function. For some controls the available reasons depend on the options provided. For example, with %gr you can add %gr[full_mouse_input].
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 1623
Location: South Pole, Antarctica

PostPosted: Fri Nov 05, 2010 2:35 pm    Post subject: Reply with quote

Got it. But from your respond follows that there is no FTN95-specific library functions for keyboard handling with OpenGL, and this has to be done via OpenGL own functions?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5007
Location: Salford, UK

PostPosted: Fri Nov 05, 2010 5:30 pm    Post subject: Reply with quote

It looks like there is some undocumented stuff in the library for handling keyboard input for OpenGL but I am not sure if it is easily accessible from Fortran. Give me a few days and I will see if I can get it to work.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5007
Location: Salford, UK

PostPosted: Fri Nov 05, 2010 5:34 pm    Post subject: Reply with quote

Correction. This is the stuff used by Ian above (glutKeyboardFunc). You need to provide a callback function (key) like that in Ian's code. Now to find the documentation...
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 1623
Location: South Pole, Antarctica

PostPosted: Sun Nov 07, 2010 1:38 pm    Post subject: Reply with quote

I will appreciate any further help, tried many things but still can not solve this damn problems of selecting 3D object by keyboard (i plan make straight on screen numbering of objects and then chose them by picking numbers from keyboard, why i need keyboard handling).

Or same can be possibly done by selecting the same objects by mouse. The mouse handling itself works with FTN95 own utilities great, but there exist another problem how select the 3D object on our actually 2D screens...You can not do that by colors (do such utilities exist?) plus the colors change in 3D due to shadowing, fog, reflections etc.(if such utilities existed and if they would ignore the color change taking just the original color of the object, then it could be possible to select objects by giving them slight variations of RGB colors)
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 468
Location: Sunderland

PostPosted: Mon Nov 08, 2010 1:51 pm    Post subject: Reply with quote

Dan,
You have to use display lists, giving each object a unique number. The when you click the mouse, you re-render the display in a GL_SELECTION mode and a small screen size of say 1 pixel by 1 pixels. This put a list of items rendered onto the reduced "screen" size into a result list which is the number of the item's display list position and hence the selected item.
I've looked at it, but never got it to work as all the examples are in C
Have a look at:

http://www.opengl.org/resources/faq/technical/selection.htm#sele0020

http://www.lighthouse3d.com/opengl/picking/

Regards
Ian
Back to top
View user's profile Send private message Send e-mail
DanRRight



Joined: 10 Mar 2008
Posts: 1623
Location: South Pole, Antarctica

PostPosted: Wed Nov 10, 2010 12:51 am    Post subject: Reply with quote

Yea, the damn thing is in C unfortunately. And the next section after display lists explains the method i described above which they call color coding.

http://www.lighthouse3d.com/opengl/picking/index.php3?color1

It has source code and explanations but again it's in C. All that easy for those who knows C and OpenGL and know this compiler OpenGL. Great would be if Paul encode all these 500 lines of C in just one single simple call to their efficient FTN95 library functions like ones CLEARWIN_INFO@ or similar:

CLEARWIN_INFO@(OpenGL_Colors) which return 3 RGB 0-255 or better typical OpenGL 4 relative 0-1 colors (one is transparency) of the point on screen with coordinates x,y (which is already provided by existing FTN95 OpenGL functions)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group