Samples/Video/VideoMemory.py
 
 
 
Samples/Video/VideoMemory.py
# Copyright 2012 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
# ...
# This scipt is to demonstrate the usage of FBVideoMemory.
# ...
#
# Topic: FBMaterial, FBTexture, FBMaterialTextureType, FBVideoMemory, FBImage
#

from pyfbsdk import * 
from OpenGL  import *
from OpenGL.GL import *

# Create a cub
lPlane = FBModelPlane("MyPlane")
lPlane.Show = True
# Move it around to let it fully visible in the viewport
lPlane.Rotation = FBVector3d(90, 0, 0)
lPlane.Translation = FBVector3d(0, 100, -200)
# Create a material
lMaterial = FBMaterial("MyMaterial")
# Create a texture
lTexture = FBTexture("MyTexture")
# Set texture to material's diffuse channel.
lMaterial.SetTexture(lTexture, FBMaterialTextureType.kFBMaterialTextureDiffuse)
# Attach material to cube
lPlane.Materials.append(lMaterial)

# Create Image pixels data buffer
lImageDim = 48      
lImageBits = OpenGL.images.createTargetArray(GL_RED, (lImageDim, lImageDim), GL_UNSIGNED_BYTE)
for row in range(lImageDim):
    for col in range(lImageDim):
        pixelValue = int((row * col) * 1.0 / pow( lImageDim -1, 2.0) * 255.0);
        lImageBits[row][col] = pixelValue

# Create GL Texture and upload image data
lGLTexIDs = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, int(lGLTexIDs))
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, lImageDim, lImageDim, 0, GL_RED, GL_UNSIGNED_BYTE, lImageBits)
glBindTexture(GL_TEXTURE_2D, 0)

# Create FBVideoMemory
lVideoMemory = FBVideoMemory("MyVideo")
lVideoMemory.SetObjectImageSize(lImageDim, lImageDim)     
lVideoMemory.TextureOGLId = int(lGLTexIDs)  #Set external OGL texture ID.

# Connect VideoMemory to Texture
lTexture.Video = lVideoMemory