So basically I am trying to draw inside the viewport using a modal operator and adding a draw handler callback function to the space. Basically that the Modal Draw template from inside Blender.
My problem is that this example uses blender image functionality to load the image itself and then load it to opengl / bgl.
I would prefer however not to do this way because I dont want to add new images inside a blend file. So i tried to draw a red rectangle using this code.
buf = Buffer(GL_INT,[768,256])
TextureID = Buffer(GL_INT,[1])
<b>for </b>x <b>in </b>range(0,768):
<b>for </b>y <b>in </b>range(256):
buf[x][y]= 150
x = x + 3
error = []
error.append(glGetError())
glGenTextures(1, TextureID)
error.append(glGetError())
glBindTexture(GL_TEXTURE_2D, TextureID.to_list()[0])
error.append(glGetError())
# GetObject(Bitmap.Handle, SizeOf(Buffer), @ Buffer)
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256,256, 0, GL_RGB, GL_INT, buf)
error.append(glGetError())
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
error.append(glGetError())
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
error.append(glGetError())
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
error.append(glGetError())
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
error.append(glGetError())
glEnable(GL_BLEND)
glEnable(GL_TEXTURE_2D)
error.append(glGetError())
glBegin(GL_QUADS)
glTexCoord2f(0, 0)
glVertex2f(0, 0)
glTexCoord2f(1, 0)
glVertex2f(300,0)
glTexCoord2f(1, 1)
glVertex2f(300, 300)
glTexCoord2f(0, 1)
glVertex2f(0, 300)
glEnd()
error.append(glGetError())
but all I am getting is a black rectangle. Any idea how exactly this could work , what I am doing wrong and how to improve it ?