Skip to content

Instantly share code, notes, and snippets.

@SimonDanisch
Created June 2, 2014 09:21
Show Gist options
  • Save SimonDanisch/f294d46df55379becaa1 to your computer and use it in GitHub Desktop.
Save SimonDanisch/f294d46df55379becaa1 to your computer and use it in GitHub Desktop.
#Find the correct type of the data
imgType = eltype(data)
if imgType == Uint8
glImgType = GL_UNSIGNED_BYTE
elseif imgType == Float32
glImgType = GL_FLOAT
elseif imgType == Int8
glImgType = GL_BYTE
else
error("Type: $(imgType) not supported")
end
id = glGenTextures()
#Texture type can be GL_TEXTURE_1D, 2D, 3D
glBindTexture(textureType, id)
#setting texture parameters for example:
glTexParameteri(textureType, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
#Selecting the right OpenGL function
if textureType == GL_TEXTURE_1D
texImageFunc = glTexImage1D
elseif textureType == GL_TEXTURE_2D
texImageFunc = glTexImage2D
elseif textureType == GL_TEXTURE_3D
texImageFunc = glTexImage3D
else
error("wrong target texture type. valid are: GL_Texture_1D, GL_Texture_2D, GL_Texture_3D")
end
#pixelDataFormat Format can be RGB, GL_RGBA, GL_LUMINANCE, and some more
#Must be provided, or can be inferred from the Image properties
texImageFunc(textureType, 0, pixelDataFormat, dims..., 0, pixelDataFormat, glImgType, data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment