1

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"
  • Wow, makes me realize how rusty my Haskell is :). And that gl+haskell feels a bit crazy, gl being a so state based. :) Is getAttrib the same as getActiveAttrib in the Haskell interface? Is the shader actually compiled and linked at that point? What happens if you put an intentional error in there? Also I notice there is some mixing of sizes for the attrib. It's 4 floats in the program but then sometimes 2 or 3. – starmole Jun 01 '14 at 07:52
  • So the shaders should be compiled and linked I don't know about getActiveAttrib. You talk about the sizes of floats is that to do with the stride, if so changing that does not change anything. – JoelWaterworth Jun 01 '14 at 08:57
  • So if you put an intentional error in the shader you get a different error during execution? The attrib thing: http://www.khronos.org/opengles/sdk/docs/man3/html/glGetVertexAttrib.xhtml is very different to http://www.opengl.org/sdk/docs/man/html/glGetActiveAttrib.xhtml - From my limited understanding of the code you want the later. But what is really happening is deep in the gl library you are using. I am sorry for not being helpful and admit that I have little idea on how to fix this. But I am a bit motivated to try Haskell+gl myself now. – starmole Jun 01 '14 at 09:14

1 Answers1

1

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