hello , im using OpenGl 1.7 , im trying to draw lines but the values of the vertices are float therefore when i draw a line x=0 , y = 1 , the line is different when u draw it using canvas , i mean in opengl 0 is in the center of the screen , but on canvas 0 is the top of the screen , i tried to mess around the camera view but im stuck , i see gl.GL_SHORT but cant see integer option , and how to use it , is there any possible way to fix measurements? my activity.width is 720 , so i want 0 in opengl to be the top left and i want to draw a line from 0 to 720 , so the values have to be in integer , and here s my code :
i created a sub that converts integer values to float
can u help me plz?tnx in advance.
B4X:
Sub glsv_Draw(gl As GL1)
' As this is running on a separate thread exceptions will cause the application to force close
' and not report the exception as would happen on the main thread so we use a Try Catch block
' to trap any errors
'The view wants to be drawn using the suppllied GL1
gl.glClear(Bit.OR(gl.GL_COLOR_BUFFER_BIT, gl.GL_DEPTH_BUFFER_BIT))
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glLoadIdentity
gl.gluLookAt(0,0,5,0,0,0, 0,1,0)
'gl.glTranslatef(-int2float(160*GetDeviceLayoutValues.Scale*1000) ,0,-int2float(SeekBar1.Value))
'gl.glOrthof(-int2float(Panel1.Width*2),int2float(Panel1.Width) ,-20,20,-1,3)
'gl.glOrthof(-int2float(SeekBar1.Value),int2float(SeekBar1.Value),-20 ,20,-1,3)
'gl.glRotatef((eyeangle/(2*3.14159))*360,0,1,0)
'gl.glRotatef((eyeangle/(2*3.14159))*360,1,0,0)
gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
gl.glVertexPointerf(2, verts)
'gl.glColor4f(1,1,1,1)
gl.glDrawArrays(gl.GL_LINE_STRIP,0,(vn/2))
End Sub
Sub glsv_SurfaceChanged(gl As GL1, width As Int, height As Int)
'Called when the surface has changed size.
gl.glViewport(0, 0, width, height)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity
Dim ratio As Float
ratio = width/height
gl.gluPerspective(45, ratio,1,100)
End Sub
Sub glsv_SurfaceCreated(gl As GL1)
'Called when the surface is created or recreated.
'Log("Created")
'Try
gl.glEnable(gl.GL_DEPTH_TEST)
gl.glDepthFunc(gl.GL_LESS)
gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
Dim lightAmbient(0),lightDiffuse(0),lightPos(0) As Float
lightAmbient=Array As Float(0.2,0.2,0.2,1)
lightDiffuse=Array As Float(1,1,1,1)
lightPos=Array As Float(1,1,1,1)
gl.glEnable(gl.GL_LIGHTING)
gl.glEnable(gl.GL_LIGHT0)
gl.glLightfv(gl.GL_LIGHT0,gl.GL_AMBIENT,lightAmbient,0)
gl.glLightfv(gl.GL_LIGHT0,gl.GL_DIFFUSE,lightDiffuse,0)
gl.glLightfv(gl.GL_LIGHT0,gl.GL_POSITION,lightPos, 0)
Dim matAmbient(0),matDiffuse(0) As Float
matAmbient=Array As Float(1,1,1,1)
matDiffuse=Array As Float(1,1,1,1)
gl.glMaterialfv(gl.GL_FRONT_AND_BACK,gl.GL_AMBIENT,matAmbient,0)
gl.glMaterialfv(gl.GL_FRONT_AND_BACK,gl.GL_DIFFUSE,matDiffuse,0)
'Catch
' catch and report any exceptions on the rendering thread to the main thread
' set the glsv.DebugFlags to DEBUG_CHECK_GL_ERROR to raise an exception immediately on a GL error
'GLException(gl)
'End Try
End Sub
i created a sub that converts integer values to float
B4X:
Sub int2float(In As Int)
Return (In / 65536)
End Sub
can u help me plz?tnx in advance.