Sverchok / SverchokRedux

A reimplementation of Sverchok
GNU General Public License v3.0
4 stars 2 forks source link

new BGL features / exploration #16

Open zeffii opened 9 years ago

zeffii commented 9 years ago

some .c code https://gist.github.com/zeffii/131fb3a0f6fc3ca117fb some untested .py code https://gist.github.com/zeffii/c210322b4b5f489b2886

zeffii commented 9 years ago

Not exactly sure where to find equivalent opengl 3.1 written in python.. I imagine the untested code comes close enough..

nortikin commented 9 years ago

bgl.GL_FLOAT( maybe? not work

zeffii commented 9 years ago

yeah, underscores :)

zeffii commented 9 years ago

the data type names are wrapped using different names .. also GLunit, becomes GL_UNSIGNED_INT I think.

zeffii commented 9 years ago

or just GL_INT I didn't even try to run that code yet @nortikin :)

nortikin commented 9 years ago

@zeffii you are amazing man, to write and not test. I cannot do like this )))

ly29 commented 9 years ago

Mmm, for me the function doesn't seem to be bound to anything, None isn't the return value but the value of the function object.

zeffii commented 9 years ago

it's possible that on OSX the openGL is different

zeffii commented 9 years ago

@nortikin apparently I can't do this either :)) because it didn't work.

But normally I do write a lot of code before attempting to run it, especially if i'm familiar with the API. let the brain compile until it needs to be tested :)

ly29 commented 9 years ago

51 functions are None when I test with the below.

>>> [f for f in dir(bgl) if getattr(bgl,f) is None]
['__doc__', 'glBindBufferBase', 'glBindBufferRange', 'glBindVertexArray', 'glColorP3ui', 'glColorP3uiv', 'glColorP4ui', 'glColorP4uiv', 'glDeleteVertexArrays', 'glFramebufferTexture', 'glGenVertexArrays', 'glGetActiveUniformBlockName', 'glGetActiveUniformBlockiv', 'glGetActiveUniformName', 'glGetActiveUniformsiv', 'glGetBufferParameteri64v', 'glGetInteger64i_v', 'glGetIntegeri_v', 'glGetMultisamplefv', 'glGetUniformBlockIndex', 'glGetUniformIndices', 'glIsVertexArray', 'glMultiTexCoordP1ui', 'glMultiTexCoordP1uiv', 'glMultiTexCoordP2ui', 'glMultiTexCoordP2uiv', 'glMultiTexCoordP3ui', 'glMultiTexCoordP3uiv', 'glMultiTexCoordP4ui', 'glMultiTexCoordP4uiv', 'glNormalP3ui', 'glNormalP3uiv', 'glSampleMaski', 'glSecondaryColorP3ui', 'glSecondaryColorP3uiv', 'glTexCoordP1ui', 'glTexCoordP1uiv', 'glTexCoordP2ui', 'glTexCoordP2uiv', 'glTexCoordP3ui', 'glTexCoordP3uiv', 'glTexCoordP4ui', 'glTexCoordP4uiv', 'glTexImage2DMultisample', 'glTexImage3DMultisample', 'glUniformBlockBinding', 'glVertexP2ui', 'glVertexP2uiv', 'glVertexP3ui', 'glVertexP3uiv', 'glVertexP4ui', 'glVertexP4uiv']
ly29 commented 9 years ago

Need to ask in IRC I guess.

zeffii commented 9 years ago
>>> len([f for f in dir(bgl) if getattr(bgl,f) is None])
48
ly29 commented 9 years ago

if was just glColorP3ui I wouldn't worry but some of functions that are in every OpenGL 3 tutorial are there.

On a happier side node. Some code to create a triangulated bbl Buffer object of vertices. Here a monkey but could be any. Could be better of course with index access to bm.faces

def create_monkey():
    bm = bmesh.new()
    bmesh.ops.create_monkey(bm)
    bmesh.ops.triangulate(bm, faces=bm.faces[:])
    bm.faces.ensure_lookup_table()
    verts = bgl.Buffer(bgl.GL_FLOAT, [len(bm.faces) * 3, 3])
    for i, face in enumerate(bm.faces):
        for j, v in enumerate(face.verts):
            verts[i * 3 + j] = v.co
    return verts
nortikin commented 9 years ago

where is opengl3 in bgl development flow?

nortikin commented 9 years ago

http://wiki.blender.org/index.php/Dev:2.8/Source/OpenGL ok i see

nortikin commented 9 years ago

we need make openGL3 branch.

ly29 commented 9 years ago

Yeah that was the idea. 2.8 will take some time.

My idea was to play here and backport as makes sense.

ly29 commented 9 years ago

Had a quick look at seems like I only have OpenGL 2.x functions. Vaguely remember that for OS X you can't have 3.X and 1.X code in the same application. So for now I guess OpenGL 2 is our target. Anyway from 2.X to 3.X seems like a simpler change. Note that this needs to be confirmed...

ly29 commented 9 years ago

http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Table-of-Contents.html

ly29 commented 8 years ago

I imagined that something like this could work but no luck.

def draw_callback_view(verts, faces):

    VERT = 0
    FACES = 1

    buffers = bgl.Buffer(bgl.GL_INT, [2])
    bgl.glGenBuffers(2, buffers)

    bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, buffers[VERT])
    bgl.glBufferData(bgl.GL_ARRAY_BUFFER, 4 * 3 * len(verts), verts, bgl.GL_STATIC_DRAW)
    bgl.glVertexPointer(3, bgl.GL_FLOAT, 0, verts)
    bgl.glEnableClientState(bgl.GL_VERTEX_ARRAY)

    bgl.glBindBuffer(bgl.GL_ELEMENT_ARRAY_BUFFER, buffers[FACES])
    bgl.glBufferData(bgl.GL_ELEMENT_ARRAY_BUFFER, 4*3*len(faces), faces, bgl.GL_STATIC_DRAW)

    bgl.glDrawElements(bgl.GL_TRIANGLES, len(faces), bgl.GL_INT, bgl.Buffer(bgl.GL_INT,[1]))

The problem being DrawElements, that needs a 0 value as a pointer, but the bgl module doesn't let me pass a 0 value but it has to be a bgl.Buffer object. Nothing sensible is drawn.