I wish to create and operate textures with integer internal format (for further interop with opencl). However it seems I've missed something important in question of mapping this texture. Here is a code sample that will say a lot more. Internal format could be switched by defining INTERNAL and DATACOPY variables.
It works pretty fine if I use float normalized internal format (GL_RGBA, GL_RGBA) for texture. The sample code will draw noisy coloured image. But once I switched to (GL_RGBA8UI, GL_RGBA_INTEGER) window becomes black.
Probably problem is only with my configuration (nvidia fermi-arch). So any help in pointing to root of my problems is appreciated.
import pygame
from OpenGL.GL import *
import os
XLEN, YLEN = 320, 200
INTERNAL, DATACOPY = GL_RGBA, GL_RGBA
#INTERNAL, DATACOPY = GL_RGBA8UI, GL_RGBA_INTEGER
pygame.init()
pygame.display.set_mode((XLEN, YLEN), pygame.DOUBLEBUF | pygame.OPENGL, 24)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0, XLEN, YLEN, 0, -1, 1)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glDisable(GL_DEPTH_TEST)
tex = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, tex)
glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL, 256, 256, 0, DATACOPY, GL_UNSIGNED_BYTE, os.urandom(4 * XLEN * YLEN))
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE:
running = False
glClearColor(0.0, 0.0, 0.0, 0.0)
glClear(GL_COLOR_BUFFER_BIT)
glEnable(GL_TEXTURE_2D)
glBegin(GL_QUADS)
glTexCoord2f(0.0, 0.0)
glVertex2f(0.0, 0.0)
glTexCoord2f(1.0, 0.0)
glVertex2f(XLEN, 0.0)
glTexCoord2f(1.0, 1.0)
glVertex2f(XLEN, YLEN)
glTexCoord2f(0.0, 1.0)
glVertex2f(0.0, YLEN)
glEnd()
glDisable(GL_TEXTURE_2D)
pygame.display.flip()
glDeleteTextures(tex)
pygame.quit()
Where is your shader? You can't use integral textures without a shader. You probably got an OpenGL error somewhere.