albert_redditt

12-01-2011, 03:52 PM

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.

carsten neumann

12-01-2011, 04:19 PM

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?

albert_redditt

12-01-2011, 05:04 PM

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.

'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

Alfonse Reinheart

12-01-2011, 06:22 PM

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.

V-man

12-02-2011, 05:06 AM

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

albert_redditt

12-02-2011, 10:06 AM

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.

Alfonse Reinheart

12-02-2011, 11:17 AM

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?

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.