Samples/Video/VideoMemory.py

Samples/Video/VideoMemory.py
1 # Copyright 2012 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 # ...
6 # This scipt is to demonstrate the usage of FBVideoMemory.
7 # ...
8 #
9 # Topic: FBMaterial, FBTexture, FBMaterialTextureType, FBVideoMemory, FBImage
10 #
11 
12 from pyfbsdk import *
13 from OpenGL import *
14 from OpenGL.GL import *
15 # pyOpenGL Library must be installed for this script to work
16 
17 # Create a cube
18 lPlane = FBModelPlane("MyPlane")
19 lPlane.Show = True
20 # Move it around to let it fully visible in the viewport
21 lPlane.Rotation = FBVector3d(90, 0, 0)
22 lPlane.Translation = FBVector3d(0, 100, -200)
23 # Create a material
24 lMaterial = FBMaterial("MyMaterial")
25 # Create a texture
26 lTexture = FBTexture("MyTexture")
27 # Set texture to material's diffuse channel.
28 lMaterial.SetTexture(lTexture, FBMaterialTextureType.kFBMaterialTextureDiffuse)
29 # Attach material to cube
30 lPlane.Materials.append(lMaterial)
31 
32 # Create Image pixels data buffer
33 lImageDim = 48
34 lImageBits = OpenGL.images.createTargetArray(GL_RED, (lImageDim, lImageDim), GL_UNSIGNED_BYTE)
35 for row in range(lImageDim):
36  for col in range(lImageDim):
37  pixelValue = int((row * col) * 1.0 / pow( lImageDim -1, 2.0) * 255.0);
38  lImageBits[row][col] = pixelValue
39 
40 # Create GL Texture and upload image data
41 lGLTexIDs = glGenTextures(1)
42 glBindTexture(GL_TEXTURE_2D, int(lGLTexIDs))
43 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
44 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
45 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, lImageDim, lImageDim, 0, GL_RED, GL_UNSIGNED_BYTE, lImageBits)
46 glBindTexture(GL_TEXTURE_2D, 0)
47 
48 # Create FBVideoMemory
49 lVideoMemory = FBVideoMemory("MyVideo")
50 lVideoMemory.SetObjectImageSize(lImageDim, lImageDim)
51 lVideoMemory.TextureOGLId = int(lGLTexIDs) #Set external OGL texture ID.
52 
53 # Connect VideoMemory to Texture
54 lTexture.Video = lVideoMemory
55 
56