Ok I stripped this down to the barest form and I still get segmentation faults here is the code. I am at a loss as this seems to be identical to C code posted in examples all over the web. Any thoughts?
I have trieddrawElements Triangles (fromIntegral 1) UnsignedInt nullPtr--(fromIntegral count)Test.withArray [ (i) | i<-[0..count-1] ] $ \p -> drawElements Points10 UnsignedInt pdrawArrays Points 1 10All three of which cause a segmentation thought. I am kind of at a loss, is it possible that the buffers are empty? If so what is the best way to check?
On Thu, Nov 18, 2010 at 8:20 AM, Balazs Komuves <bkomuves@gmail.com> wrote:
Hi,
I'm just guessing here, but I believe the problem is with the linedrawElements Triangles (fromIntegral count) UnsignedInt nullPtr
Look up 'drawElements' in the OpenGL specification
(page 29 in http://www.opengl.org/documentation/specs/version2.0/glspec20.pdf):
The commandvoid DrawElements( enum mode, sizei count, enum type, void *indices );
constructs a sequence of geometric primitives using the count elements whose indices are stored in indices. type must be one of UNSIGNED BYTE, UNSIGNED SHORT, or UNSIGNED INT, indicating that the values in indices are indices of GL type ubyte, ushort, or uint respectively. Mode specifies what kind of primitives are constructed; it accepts the same token values as the mode
parameter of the Begin command. The effect of DrawElements (mode, count, type, indices); is the same as the effect of the command sequenceif (mode, count, or type is invalid )
generate appropriate error
else {
Begin(mode);
for (int i = 0; i < count ; i++)
ArrayElement(indices[i]);
End();
}Balazs
So, I think you actually want to use 'drawArrays' instead. But without seeing the full source, I'm again just guessing.
I believe 'drawElements' should be used like this (I'm writing this from the top of head, so take it with a grain of salt):
withArray [ (3*i :: GLuint) | i<-[0..count-1] ] $ \p -> drawElements Triangles count UnsignedInt p
On Thu, Nov 18, 2010 at 2:53 AM, Ben Christy <ben.christy@gmail.com> wrote:
_______________________________________________I am having a issue getting a seg fault with drawElements. Honestly I can not tell where the problem is. It seems as far as all I have read that it should work and being its written in haskell I am asking here first before asking in an opengl chat room.I init my VBOs withinitModelIBO :: Int → IO BufferObjectinitModelIBO listLen = doprint "list length"print listLenprint "gen ibo bytes"print sizeOfList[ibo] ← genObjectNames 1 :: IO [BufferObject]bindBuffer ElementArrayBuffer $= Just ibotempArray2 ← newListArray (0, listLen - 1) indexList :: IO(StorableArray Int GLuint)withStorableArray tempArray2 (λptr ->bufferData ElementArrayBuffer $= ((fromIntegral sizeOfList), ptr, StaticDraw))bindBuffer ElementArrayBuffer $= Nothingreturn ibowhereelementSize = 4sizeOfList = listLen * elementSizeindexList = [i | i ← [0..(fromIntegral listLen)]] :: [GLuint]initModelVBO :: [Vert] → IO BufferObjectinitModelVBO vertexList = doprint "list length"print listLenprint "gen vbo bytes"print sizeOfList[vbo] ← genObjectNames 1 :: IO [BufferObject]bindBuffer ArrayBuffer $= Just vbotempArray ← newListArray (0, listLen - 1) vertList :: IO(StorableArray Int GLfloat)withStorableArray tempArray (λptr ->bufferData ArrayBuffer $= ((fromIntegral sizeOfList), ptr, StaticDraw))bindBuffer ArrayBuffer $= Nothingreturn vbowhereelementsPerVert = 10vertList = vertsToList vertexListlistLen = length vertListelementSize = 4sizeOfList = listLen * elementSizeMy Vert type isdata Vert = Vert {vertX ::GLfloat,vertY ::GLfloat,vertZ ::GLfloat,--normalX ::GLfloat,--normalY ::GLfloat,--normalZ ::GLfloat,colorR ::GLfloat,colorG ::GLfloat,colorB ::GLfloat,specR ::GLfloat,specG ::GLfloat,specB ::GLfloat,shiny ::GLfloat}deriving (Show)I set vertex attributes withsetAttribPtr (Just program) = doprint " Setting attrib pointer"--vertexAttribPointer (AttribLocation 1) $= (KeepIntegral, (VertexArrayDescriptor 3 Float ((4) *10) (plusPtr nullPtr (0*4))))GLRaw.glVertexAttribPointer 1 3 GLRaw.gl_FLOAT 0 stride (plusPtr nullPtr (0))vertexAttribArray (AttribLocation 1) $= Enabled--vertexAttribPointer (AttribLocation 2) $= (KeepIntegral, (VertexArrayDescriptor 3 Float ((4) *10) (plusPtr nullPtr (3*4))))GLRaw.glVertexAttribPointer 2 3 GLRaw.gl_FLOAT 0 stride (plusPtr nullPtr (12))vertexAttribArray (AttribLocation 2) $= Enabled--vertexAttribPointer (AttribLocation 3) $= (KeepIntegral, (VertexArrayDescriptor 3 Float ((4) *10) (plusPtr nullPtr (6*4))))GLRaw.glVertexAttribPointer 3 3 GLRaw.gl_FLOAT 0 stride (plusPtr nullPtr (24))vertexAttribArray (AttribLocation 3) $= Enabled--vertexAttribPointer (AttribLocation 4) $= (KeepIntegral, (VertexArrayDescriptor 1 Float ((4) *10) (plusPtr nullPtr (9*4))))GLRaw.glVertexAttribPointer 4 1 GLRaw.gl_FLOAT 0 stride (plusPtr nullPtr (36))vertexAttribArray (AttribLocation 4) $= Enabledreturn ()wherestride = 40I build a shader program withbuildShader vertexShader fragmentShader = do[vertObj] ← genObjectNames 1 ::IO [VertexShader]shaderSource vertObj $= [vertexShader]compileShader vertObjvsLog ← get (shaderInfoLog vertObj)print "vertex shader status"print vsLog[fragObj] ← genObjectNames 1 ::IO [FragmentShader]shaderSource fragObj $= [fragmentShader]compileShader fragObjfsLog ← get (shaderInfoLog fragObj)print "fragment shader status"print fsLog[programObj] ← genObjectNames 1 ::IO [Program]attachedShaders programObj $= ([vertObj], [fragObj])attribLocation programObj "position" $= AttribLocation 1attribLocation programObj "color" $= AttribLocation 2attribLocation programObj "spec" $= AttribLocation 3attribLocation programObj "shiny" $= AttribLocation 4linkProgram programObjprogLog ← get(programInfoLog programObj)print "Shader Program status"print progLogreturn (Just programObj)Finally my render functioninstance RenderSimpleSceneGraph Model whererender matrix (ModernModel vbo ibo shader count) = doclientState VertexArray $= Enabledversion ← get (majorMinor glVersion)tempVBO ← vbotempIBO ← iboprint "Render Modern Model"program ← shadercurrentProgram $= programbindBuffer ArrayBuffer $= Just tempVBOsetAttribPtr programbindBuffer ElementArrayBuffer $= Just tempIBOprint "here"drawElements Triangles (fromIntegral count) UnsignedInt nullPtrprint "here1"resetAttribPtr programbindBuffer ArrayBuffer $= NothingclientState VertexArray $= Disabled
HOpenGL mailing list
HOpenGL@haskell.org
http://www.haskell.org/mailman/listinfo/hopengl