Haskell opengl attrib is not active

171 views Asked by At

I am trying to render some data from a vertex buffer object. However with little using glutil and raw. When the program runs it is stuck in a infinite loop and I get the errors that you see down below.

vertex shader

#version 150 core

in vec4 position;

void main (void)
{
    gl_Position = position;

}

fragment shader

#version 150 core

out vec4 color;

void main (void)
{
    color = vec4(0.0, 0.8, 1.0, 1.0);
}

I have tried using 430 but that didn't work. So I tried using 150 as I saw a lot people using it. Furthermore I have tried using layout while using raw but that didn't work.

instance of use

mesh :: [GLfloat]
mesh = [ 0.25, -0.25, 0.5
       ,-0.25, -0.25, 0.5
       , 0.25,  0.25, 0.5]

preMainLoop :: G.Window -> IO ()
preMainLoop window = do
    p <- loadShaderProgram [ ( VertexShader,   "frag.fs")
                           , ( FragmentShader, "vert.vs")]
    myVBO <- makeBuffer ArrayBuffer mesh
    vao <- makeVAO $ let vad = VertexArrayDescriptor 3 Float stride offset0"
                     in do
                         printErrorMsg "something else"
                         currentProgram $= Just (program p)
                         printErrorMsg "program"
                         bindBuffer ArrayBuffer $= Just myVBO
                         printErrorMsg "buffer"
                         enableAttrib p "position"
                         printErrorMsg "attribLocation"
                         setAttrib p "position" ToFloat vad
                         bindBuffer ArrayBuffer $= Nothing
    mainLoop window vao p

errors

program
WARNING: attrib position is not active
  GL: Error InvalidOperation "invalid operation"
1

There are 1 answers

0
JoelWaterworth On

So I tried testing my code with the opengl raw and this caused it to yield my desired results.

loc <- withCString "position" $ \pos -> glGetAttribLocation p pos
bindBuffer ArrayBuffer $= Just buffer
glEnableVertexAttribArray (fromIntegral loc)
glVertexAttribPointer (fromIntegral loc) 3 gl_FLOAT (fromIntegral gl_FALSE) 8 nl