Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Android OpenGL

I have been having problems with tracking my 2d objects in OpenGL using Ajhc.

I don't know how I can keep track of my object and prevent it from leaving the width and height of the device. Can anyone provide assistance?

My code here:

module Draw where
import CubeVerts
import CoSys
import AndroidNdk
import AndroidNdk.Log

import Foreign.Marshal.Array

spriteMv :: Float -> Float -> Float -> Float -> Float -> IO ()
spriteMv x y dx dy z = do
    drawFunc

drawFunc :: IO ()
drawFunc = do
    c_glDrawArrays c_GL_TRIANGLES 0 6

spritePlayer :: Float -> Float -> Float -> Float -> Float -> IO ()
spritePlayer x y dx dy z = do
    withArray vertices $ λvp -> withArray colors $ λcp -> do
    c_glEnableClientState c_GL_VERTEX_ARRAY
    c_glEnableClientState c_GL_COLOR_ARRAY
    c_glVertexPointer 3 c_GL_FLOAT 0 vp
    c_glColorPointer 4 c_GL_FLOAT 0 cp

    spriteMv x y dx dy z

    c_glDisableClientState c_GL_VERTEX_ARRAY
    c_glDisableClientState c_GL_COLOR_ARRAY
like image 862
Archxiao Avatar asked Mar 08 '14 05:03

Archxiao


1 Answers

(my experience with Haskell and OpenGL is not on Android, and is a few years old).

Create an IORef. You need to save the object's position and retrieve it from your callbacks. See chapter 5 of Sven Panitz's Haskell/OpenGL tutorial on: HOpenGL

like image 70
ja. Avatar answered Oct 14 '22 15:10

ja.