Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
openGL and the mouse?
#1
howdy! im trying to make a level editor for a game im making!
and along the way im learning openGL, so im new and real green with openGL, but i just learned that the regular mouse function in freebasic doesnt work to well with OGL, can any one help?

much appreciated, and thanx!
t is better to error on the side of caution
than the side of haste!!!
[Image: title3.jpg]
Reply
#2
What helper lib are you using? I mean GLFW, GFgfxlib, SDL, Glut or something else? They should work though... just maybe not as expected. You have to remember that a gl window reverses the y coordinate system.

Also, what exactly are you trying to do? If you're trying to select 3D objects, there are a few ways to do it, but in my opinion, the easiest wold be to use OpenGL's built in picking utilities. Wink
Reply
#3
YA! i tryed glfw but to no avail, and SDL looks like french to me!
im trying to work out GLUT right now! but all my manuals doent use it or have any ref to it! so im looking for some thing on line right now to help!

GLFW seems simple but every time i tryed to use it with my exsisting GLcode it would freeze!
but on its own it worked perfect!
t is better to error on the side of caution
than the side of haste!!!
[Image: title3.jpg]
Reply
#4
GLFW shouldn't freeze up... it's the most reliable that I have found. How big is your code? I cold take a look at it, as long as it isn't real long. Wink
Reply
#5
Code:
#include "gl\gl.bi"
#include "gl\glfw.bi"
dim shared a,b as integer
glfwInit()
glfwOpenWindow( 640, 480 , 5, 6, 5, 0, 0, 0, GLFW_WINDOW )
glClearColor( .0, .0, .0, .0 )
glfwEnable GLFW_MOUSE_CURSOR
'lfwEnable GLFW_MOUSE_CURSOR

do:
glClear( GL_COLOR_BUFFER_BIT )
glfwSwapBuffers()  
glfwGetMousePos (@a,@b)
'glfwGetMouseButton glfw_press
locate 2,1:?"           "
locate 3,1:?"           "
locate 1,1:? a,b
locate 3,1:? glfwGetMouseWheel
if glfwGetMouseButton(GLFW_MOUSE_BUTTON_left) then locate 2,1:?"left"
if glfwGetMouseButton(GLFW_MOUSE_BUTTON_right) then locate 2,1:?"right"
if glfwGetMouseButton(GLFW_MOUSE_BUTTON_middle) then locate 2,1:?"mid"
loop
this is my mouse in GLFW, here it works fine!

Code:
#include "gl/gl.bi"
#include "GL/glu.bi"
#include "GL/glut.bi"
randomize timer
screen 19, 32, , 2
dim shared grid_size as single
dim shared modx,mody,zoom,m1,m2,m3,m4 as integer

sub drawmap
        glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
        glLoadIdentity                                    
        'modx=0:mody=0:zoom=-15
        grid_size=.1
        glTranslatef modx,mody,zoom
        glRotatef 180,1.0, .0, .0                          
        glBegin GL_lines
            glColor3f .1,.1,.1
            for i!=-50 to 50 step grid_size
                    glVertex2f i!,-50
                    glVertex2f i!,50
                    glVertex2f -50,i!
                    glVertex2f 50,i!
            next i
        glend
        
        glBegin GL_points
            glColor3f 0,0,.5
            glVertex2f 0,0
            glVertex2f 1,0
            glVertex2f 1,1
            glVertex2f 0,1
        glEnd
        flip
end sub


    glViewport 300, 100, 500, 500  
    glMatrixMode GL_PROJECTION      
    glLoadIdentity                  

    'glOrtho -10,10,-10,10,-50,50
    'glFrustum -10,10,-10,10,-50,50
    gluPerspective 54,1 , 0, 100
    glMatrixMode GL_MODELVIEW
    glLoadIdentity          
    
    
    glEnable GL_TEXTURE_2D  
    glShadeModel GL_smooth                      
    glClearColor 0.0, 0.0, 0, .50                
    glClearDepth 1.0                              
    glEnable GL_DEPTH_TEST                        
    glDepthFunc GL_LEQUAL                          
    glHint GL_LINE_SMOOTH_HINT, GL_NICEST
    GL_LINE_SMOOTH_HINT
    glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
    glEnable GL_CULL_FACE
    glFrontFace(GL_cw)
    glCullFace(GL_front)
    glpointsize 3
    modx=0:mody=0:zoom=-15
    drawmap
    do
        'glutMouseFunc
        'GETMOUSE m1, m2,m3, buts
        'WINDOWTITLE str(buts)
        'if buttons=3 then'and
        'if m3=+1 then
        '    zoom-=1
        '    if zoom<-100 then zoom=-100
        '    m3=0
            'drawmap
        'end if
        
    loop while inkey$ = ""
now i put it in to here, cause i want the scroll button to zoom in and out!
i had the GLFW in this code, but i didn't save it cause it was all screwy!

ps. keep in mine i have little knowledge of OGL, i may have extra in there i don't need or there may be a better way! i don't know!
but any help would be appreciated!
t is better to error on the side of caution
than the side of haste!!!
[Image: title3.jpg]
Reply
#6
Sorry, I almost forgot about this! I've been playing LL to much. :oops:

All I did was stick GLFW back in there and show how you could zoom in using the mousewheel. Hope it helps. Wink

Code:
#include "gl/gl.bi"
#include "GL/glu.bi"
#include "GL/glfw.bi"


randomize timer
dim shared grid_size as single
dim shared modx,mody,zoom,m1,m2,m3,m4 as integer
Dim As Integer MouseX, MouseY, MouseWheel

Declare sub drawmap ()


If glfwInit() Then
    'success!!!
Else
    Print "Failed to initialize GLFW!!!"
    Sleep 1000
    End
End If

If glfwOpenWindow( 640, 480 , 5, 6, 5, 0, 0, 0, GLFW_WINDOW ) Then
    'success
Else
    glfwTerminate()
    Print "Failed to create OpenGL context!!!"    
    Sleep 1000
    End
End If

glClearColor( .0, .0, .0, .0 )
glfwEnable GLFW_MOUSE_CURSOR





    glViewport 300, 100, 500, 500    
    glMatrixMode GL_PROJECTION      
    glLoadIdentity                  

    'glOrtho -10,10,-10,10,-50,50
    'glFrustum -10,10,-10,10,-50,50
    gluPerspective 54,1 , 0, 100
    glMatrixMode GL_MODELVIEW
    glLoadIdentity            
    
    
    glEnable GL_TEXTURE_2D    
    glShadeModel GL_smooth                        
    glClearColor 0.0, 0.0, 0, .50                
    glClearDepth 1.0                                
    glEnable GL_DEPTH_TEST                          
    glDepthFunc GL_LEQUAL                          
    glHint GL_LINE_SMOOTH_HINT, GL_NICEST
    GL_LINE_SMOOTH_HINT
    glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
    glEnable GL_CULL_FACE
    glFrontFace(GL_cw)
    glCullFace(GL_front)
    glpointsize 3
    modx=0:mody=0:zoom=-15
    drawmap
    
    do
        
        glfwGetMousePos(@MouseX, @MouseY)
        MouseWheel = glfwGetMouseWheel()
        zoom = mousewheel
        'glutMouseFunc
        'GETMOUSE m1, m2,m3, buts
        'WINDOWTITLE str(buts)
        'if buttons=3 then'and
        'if m3=+1 then
        '    zoom-=1
        '    if zoom<-100 then zoom=-100
        '    m3=0
            drawmap
        'end if
   Print MouseWheel
   glfwSwapbuffers()
   loop while glfwGetKey(GLFW_KEY_ESC) = GLFW_RELEASE

glfwTerminate()










sub drawmap ()
      glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
        glLoadIdentity                                      
      'modx=0:mody=0:zoom=-15
        grid_size=.1
        glTranslatef modx,mody,zoom
        glRotatef 180,1.0, .0, .0                          
        glBegin GL_lines
            glColor3f .1,.1,.1
            for i!=-50 to 50 step grid_size
                    glVertex2f i!,-50
                    glVertex2f i!,50
                    glVertex2f -50,i!
                    glVertex2f 50,i!
            next i
        glend
        
        glBegin GL_points
            glColor3f 0,0,.5
            glVertex2f 0,0
            glVertex2f 1,0
            glVertex2f 1,1
            glVertex2f 0,1
      glEnd
      
end sub
Reply
#7
thank buddy your going in the credits!
t is better to error on the side of caution
than the side of haste!!!
[Image: title3.jpg]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)