Results 1 to 7 of 7

Thread: OpenGl parsing

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2011
    Location
    Santa Barbara
    Posts
    7

    OpenGl parsing


    How would you pass an equation to OpenGl.

    r1=atn(1)/45
    d1=0 to 360
    c1=cos(d1*r1)
    s1=sin(d1*r1)

    str x = "c1*s1*cos(log(d1*r1*c1)*s1)"

    how could you hand string x to GL?
    What i'm doing now is using a slow parser to get the result of the string and passing the result to the GL_List.

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: OpenGl parsing

    You can not pass equations to OpenGL, it only deals with graphic primitives (triangles, lines, points) for which you specify attributes (positions, normals, etc.).
    If you have a parametric description of a surface you can evaluate and use the resulting positions to render a graphical representation of the surface.

    In the same way it is not possible to pass strings to OpenGL. There are libraries that can render text using OpenGL or you can code that functionality yourself.

    GL_List is not the name of any type that is part of the OpenGL API, are you sure you want to use OpenGL and are not dealing with some other library that uses the (upper case) GL prefix?

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2011
    Location
    Santa Barbara
    Posts
    7

    Re: OpenGl parsing

    What I want it to do is; allow the user to enter the formula and then plot it in OpenGL.

    Maybe I should put it in as a Feature_Request?
    Heres a sample.

    Code :
     
    'Written in FreeBasic.023 for windows
    '
    'to get latest version:
    'http://www.freebasic.net/forum/viewtopic.php?t=18320
    '
    'For a real easy to use Integrated Development Enviroment. FBIDE
    'http://fbide.freebasic.net/index.php?menuID=56
    '
    '=================================
    'Begin code
    '=================================
    #include once "GL/gl.bi"
    #include once "GL/glu.bi"
     
    'console printed instructioins.
    screen 0
    cls
    print "Press Esc to EXIT"
    print "-----------------------------------------"
    print
    print "Press Space-bar to stop all motion       "
    print
    print "-----------------------------------------"
    print "Left , Right Arrows to rotate on X - Axis"
    print
    print "  Up ,  Down Arrows to rotate on Y - Axis"
    print
    print " R_Shft to reset U/D , L/R rotate values "
    print "-----------------------------------------"
    print
    print " (+) , (-) , (Enter) to control spin     "
    print
    print " (Q) , (W) , (E) to control zoom level   "
    print
    print " (A) , (S) , (D) to control U/D shift    "
    print
    print " (Z) , (X) , (C) to control L/R shift    "
    print
    print " (R) , (T)       to control RED   LEVEL  "
    print " (F) , (G)       to control GREEN LEVEL  "
    print " (V) , (B)       to control BLUE  LEVEL  "
    print "-----------------------------------------";
     
    'for general trig looping and values
    '======================================
    dim as double r1       = atn(1)/90
    dim as double d1
    dim as double deg1_start =   0
    dim as double deg1_end   = 360
    dim as double deg1_inc   =   1
    '======================================
    dim as double r2       = atn(1)/45  
    dim as double d2
    dim as double deg2_start =   0
    dim as double deg2_end   = 360
    dim as double deg2_inc   =   .5
    '======================================
    dim as double c1
    dim as double c2
    dim as double s1
    dim as double s2
     
    dim as double out_x
    dim as double out_y
    dim as double out_z
     
    dim as integer xres,yres
    windowtitle "Abstract-147"
    screen 19
    screeninfo xres,yres
    Screenres xres,yres,32,1,2
     
    ' create and compile a OpenGL list
    dim as integer glList = glGenLists(1)
    glNewList(glList, GL_COMPILE)
    glBegin GL_POINTS
     
        For d1 = deg1_start To deg1_end Step deg1_inc
     
            c1=cos(d1*r1)
            s1=sin(d1*r1)
     
            For d2 = deg2_start To deg2_end Step deg2_inc
     
                c2=cos(d2*r2)
                s2=sin(d2*r2)
     
                dim as single x : x =(c1*cos(cos(d2*r2)*s2/c1))*2
     
                dim as single y : y =(s1*sin(sin(d2*r2)*c2/s1))*2
     
                dim as single z : z = c2+s2
     
                glvertex3f x , y , z
     
            Next d2
     
        Next d1    
    glEnd
    glEndList()
     
    '===============================================================================
    '===============================================================================
    glMatrixMode GL_PROJECTION
    glLoadIdentity
    gluPerspective 18 , xres/yres , .1, 500
    glMatrixMode GL_MODELVIEW
    glLoadIdentity
    glBlendfunc GL_SRC_ALPHA, GL_ONE
    glPointsize 1
    glEnable gl_blend
     
    'for OpenGl transition,rotation
    dim as single xt, yt, zt=-15  'transition variables
    dim as single xr, yr, zr      'rotation variables
    dim as single xrs=.5,yrs=.5,zrs=.5' transitions of camera
    dim as ubyte red= 150, green=75, blue=25
     
    dim as ubyte status=1
    DO WHILE status=1
     
      glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
      glloadidentity
     
      gltranslatef xt, yt, zt
      glrotatef xr, 1, 0, 0
      glrotatef yr, 0, 1, 0
      glrotatef zr, 0, 0, 1       
     
      ' draw the list
      glColor3ub red,green,blue
      glCallList glList     
     
      'screensync
      glFlush
      flip
     
        'check for keys being pressed
        if multikey(&h01) then status = 0 ' esc key to quit
     
        xrs = xrs + (multikey(&h50)/10) - (multikey(&h48)/10) 'left & right arrows
        yrs = yrs + (multikey(&h4D)/10) - (multikey(&h4B)/10) 'up & down arrows
        zrs = zrs + (multikey(&h0C)/10) - (multikey(&h4E)/10) 'plus & minus on the keypad
     
        xr = xr - xrs
        yr = yr - yrs
        zr = zr - zrs
     
        zt = zt + ((multikey(&h10)/2) - (multikey(&h11)/2)) ' q , w zoom in out
        yt = yt + ((multikey(&h1E)/2) - (multikey(&h1F)/2)) ' a , s shift left,right
        xt = xt + ((multikey(&h2C)/2) - (multikey(&h2D)/2)) ' z , x shift up,down
     
        red   = red   +((multikey(&h13)) - (multikey(&h14))) ' r , t adjust red level
        green = green +((multikey(&h21)) - (multikey(&h22))) ' f , g adjust green level
        blue  = blue  +((multikey(&h2f)) - (multikey(&h30))) ' v , b adjust blue level
     
        if multikey(&h39) then xrs=0 : yrs=0 : zrs=0  ' SPACE-BAR = stop all transitions
     
        if multikey(&h1C) then  xr=0 :  yr=0 : zr=0   ' "Enter Key" reset spin to zero
     
        if multikey(&h36) then 'right_shift key, to reset GL_X,GL_Y rotation values
            xrs=0:yrs=0
            xr =0:yr =0
        end if
     
        if multikey(&h12) then zt=-15        ' "E key" reset zoom level
        if multikey(&h20) then yt= 0         ' "D key" reset UP/DOWN    position to center
        if multikey(&h2E) then xt =0         ' "C key" reset Left/Right position to center
     
    Loop
     
    END

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,671

    Re: OpenGl parsing

    Maybe I should put it in as a Feature_Request?
    OpenGL should not be plotting functions; that's not its job. It is a low-level rendering system. If you want to plot a function, it is up to you to evaluate that function, then draw a series of lines that represent the plotted function.

    That's how low-level rendering systems work: you tell them exactly what to draw.

  5. #5
    V-man
    Guest

    Re: OpenGl parsing

    GL exposes what the GPU can do. And the GPU is a graphics renderer.

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2011
    Location
    Santa Barbara
    Posts
    7

    Re: OpenGl parsing

    It would be nice if you could:

    glfloat r1=??
    glfloat d1=??
    glfloat c1=??
    glfloat s1=??
    glformula = "user input using allocated variables."

    Whats the difference between a hard coded equation and a user input equation thats the same equation.

    If you use a parser with the glList then depending on the equation you are looking at 30 seconds to 5 or more minutes to
    fill the list. So a user would type in x,y,z equations and then have to wait maybe 5 minutes for the display to show up.

  7. #7
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,671

    Re: OpenGl parsing

    It would be nice if you could:
    It would be nice if OpenGL could also play sounds or run a game engine. That doesn't mean it ought to be doing that.

    If you use a parser with the glList then depending on the equation you are looking at 30 seconds to 5 or more minutes to
    fill the list. So a user would type in x,y,z equations and then have to wait maybe 5 minutes for the display to show up.
    What kind of CPU are you running that computing points on a function takes 0.5 to 5 seconds? What kind of function is this? Hardcore packages like Mathematica/Matlab/etc and such don't take that long for most functions, so why do you think that your program would?

Similar Threads

  1. Parsing a OBJ file for opengl APIs
    By kwcoffee1 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-13-2013, 04:15 PM
  2. Would like a guide for parsing...
    By MolmasEpic in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-08-2011, 01:05 PM
  3. OpenGL Spec Parsing
    By cNoNim in forum OpenGL: Linux
    Replies: 0
    Last Post: 04-15-2010, 03:03 PM
  4. Parsing Collada!
    By golgoth13 in forum COLLADA
    Replies: 3
    Last Post: 03-31-2006, 02:04 PM
  5. Parsing RFX files etc.
    By eyebex in forum OpenGL: GLSL
    Replies: 5
    Last Post: 11-30-2004, 11:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean