Archxiao
Archxiao

Reputation: 199

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

Upvotes: 15

Views: 989

Answers (1)

ja.
ja.

Reputation: 4249

(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

Upvotes: 2

Related Questions