opengl - I can't get a simple indexed array rendered properly -


i porting sample (site) jogl noticed wasn't perfect in image, artefacts on floor , shapes not squared, can see (dont care color, varying), floor doesnt good:

enter image description here

enter image description here

therefore tried render floor first (if wanna try, pretty easy, swith sqrt_building_count 100 -> 0) , there have first problems, supposed square based on 2 triangles, see 1 of them.

enter image description here

my vertex structure:

public float[] position = new float[3]; public byte[] color = new byte[4]; public float[] attrib0 = new float[4]; public float[] attrib1 = new float[4]; public float[] attrib2 = new float[4]; public float[] attrib3 = new float[4]; public float[] attrib4 = new float[4]; public float[] attrib5 = new float[4]; public float[] attrib6 = new float[4]; 

attrib0-6 unused @ moment

my vs inputs:

// input attributes layout(location=0) in vec4 ipos; layout(location=1) in vec4 icolor; layout(location=2) in permeshuniforms* bindlesspermeshuniformsptr; layout(location=3) in vec4 iattrib3; layout(location=4) in vec4 iattrib4; layout(location=5) in vec4 iattrib5; layout(location=6) in vec4 iattrib6; layout(location=7) in vec4 iattrib7;  

i declaring ipos vec3, guess padded vec4(ipos, 1) in vs

i transfer data gpu:

    gl4.glnamedbufferdata(vertexbuffer[0], vertex.size() * vertices.size(),             glbuffers.newdirectfloatbuffer(verticesarray), gl4.gl_static_draw);     gl4.glnamedbufferdata(indexbuffer[0], glbuffers.sizeof_short * indices.size(),             glbuffers.newdirectshortbuffer(indicesarray), gl4.gl_static_draw); 

then before render i call:

        gl4.glenablevertexarrayattrib(0, 0);         gl4.glenablevertexarrayattrib(0, 1); 

then render, original code is:

    // set attribute 0 position (3 floats)     glvertexarrayvertexattriboffsetext(0, m_vertexbuffer, 0, 3, gl_float, gl_false, sizeof(vertex), vertex::positionoffset);      // set attribute 1 color (4 unsigned bytes)     glvertexarrayvertexattriboffsetext(0, m_vertexbuffer, 1, 4, gl_unsigned_byte, gl_true, sizeof(vertex), vertex::coloroffset); 

i substituted with:

        // set attribute 0 position (3 floats)         gl4.glvertexarrayvertexbuffer(0, 0, vertexbuffer[0], vertex.positionoffset,                 vertex.size());         gl4.glvertexarrayattribformat(0, 0, 3, gl4.gl_float, false, vertex.size());          // set attribute 1 color (4 unsigned bytes)         gl4.glvertexarrayvertexbuffer(0, 1, vertexbuffer[0], vertex.coloroffset,                 vertex.size());         gl4.glvertexarrayattribformat(0, 1, 4, gl4.gl_unsigned_byte, true, vertex.size()); 

and finish render:

        // reset state         gl4.gldisablevertexarrayattrib(0, 0);         gl4.gldisablevertexarrayattrib(0, 1); 

i admit never used dsa before, used gl3 normal vbo, vao , ibo, binding , unbinding..

culling off.

what's wrong then?

solved, problem didnt implement dsa

glenablevertexattribarray(vao, 0); glenablevertexattribarray(vao, 1);  // setup formats glvertexarrayattribformat(vao, 0, 3, gl_float, gl_false, 0); glvertexarrayattribformat(vao, 1, 2, gl_float, gl_false, 0);  // setup buffer sources glvertexarrayvertexbuffer(vao, 0, buffers[0], 0, 0); // note 2nd argument here 'binding index', not attribute index glvertexarrayvertexbuffer(vao, 1, buffers[1], 0, 0);  // link them glvertexarrayattribbinding(vao, 0, 0); // associate attrib 0 (first 0) binding 0 (second 0). glvertexarrayattribbinding(vao, 1, 1); 

plus glvertexarrayelementbuffer if have indexed rendering


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -