Help with Test Gui script...


(BaDbOyHeRe) #1

this script allows one to import a bitmap image and show it when the script is run. Who created it? I need to know what to change in order to allow for a 320x240 bitmap to be displayed properly. currently is only allows 256x256. The following is the original script. Any help would be wonderful. I just need to be pointed in the right direction. thank you…


import Blender
from Blender.BGL import *

global WinSize
# ||||||||||||||||||||||||||||||||||||||||||||||||||
# Most important! This is my OpenGL drawing routine...:)
def MyDraw():
	global WinSize
	glClearColor(.2,.1,.2,0)
	glClear(GL_COLOR_BUFFER_BIT)
	glGetFloatv(GL_SCISSOR_BOX,WinSize)
	MyButton = Blender.Draw.Button('exit',20,20,120,50,50)	
	# Do the OpenGL drawing here...
	glEnable(GL_TEXTURE_2D)
	glBegin(GL_QUADS)
	glTexCoord2f(1.0,1.0)
	glColor3f(1.0,1.0,1.0)
	glVertex2d(10,10)
	glTexCoord2f(0.0,1.0)
	glColor3f(1.0,1.0,1.0)
	glVertex2d(WinSize[2],10)
	glTexCoord2f(0.0,0.0)
	glColor3f(1.0,1.0,1.0)
	glVertex2d(WinSize[2],WinSize[3])
	glTexCoord2f(1.0,0.0)
	glColor3f(1.0,1.0,1.0)
	glVertex2d(10,WinSize[3])
	glEnd()
	glDisable(GL_TEXTURE_2D)
# You have to use glEnable/glDisable because if you don't, you
# will draw into Blender's screen area too, it really messes it up!
# This keeps the texture drawing local to your object!
#''''''''''''''''''''''''''''''''''''''''''''''''
# Event function handlers
def MyEvent(eventnum,eventmod):


	if eventnum == Blender.Draw.RIGHTMOUSE:
		pass
	
		
	if eventnum == Blender.Draw.MOUSEX:
		pass

	if eventnum == Blender.Draw.MOUSEY:
		pass		
		
	if eventnum == Blender.Draw.LEFTMOUSE:
		pass
	

def ButtonEvent(num):
	if num == 20:
		Blender.Draw.Exit()
			
#''''''''''''''''''''''''''''''''''''''''
#====================================
# load the bitmap file...into "memory"
bitfile = open('c:/program files/blender/test1.bmp','rb')
filedata = []
filedata = bitfile.read()
bitfile.close()
#====================================
# ---------------------------------------
# this is where the bits of the bitmap data are loaded
# into a Buffer object for passing to OpenGL
# NOTE: In a 24 bit bitmap or above, data always starts
# at offset Hex 36 - decimal 54.
filedata = filedata[54:]
texdata = []
for v in range(len(filedata)):
	texdata.append(ord(filedata[v]))
# have to reverse the data in memory....
texdata.reverse()
texbuff = Buffer(GL_BYTE,len(filedata))
for v in range(len(filedata)):
	texbuff[v] = texdata[v]
# ----------------------------------------
# ++++++++++++++++++++++++++++++++++++++++
# Set up the OpenGL texture parameters
glPixelStorei(GL_UNPACK_ALIGNMENT,1)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE)
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,256,256,0,GL_RGB,GL_UNSIGNED_BYTE,texbuff)
# ++++++++++++++++++++++++++++++++++++++++
# image is in video mem. now, so we can delete it 
# from our memory
del filedata
del texbuff
del texdata
# get the window size
WinSize = Buffer(GL_FLOAT,4)
glShadeModel(GL_SMOOTH)
Blender.Draw.Register(MyDraw,MyEvent,ButtonEvent)

thanks again

BaDbOyHeRe 8)


(eeshlo) #2

I think this was done by nikolatesla20? I originally wanted to use a similar method to display the picture for the LF script, but although the display quality is better (OGL interpolates the colours), the disadvantage is that you can only use powers of two for the image size (up to 1024, less or more depending on your driver/card). So to display an image with different image size you either have to resample the image to make both width and height a power of 2, or you cut up the picture in smaller ones that are powers of two and use more textured quads.
That is why I decided to use something similar to Jean-Michel Soler’s code to display the picture, which simply directly draws a pixelbuffer. This doesn’t look as good as textured quads (no interpolation) but has the advantage that you can easily make it work for any image size.


(BaDbOyHeRe) #3

I found Soler’s script. I already had it. Since I am new to python, I failed terribly to get a .bmp file to work with it. Also, have had no luck in loading any tga files with different sizes. I really could use some more knowledge which I am slowly learning. I’ve been digging into pythons PIL library and can’t seem to get it working with blender. I get a c module not compiled error when I try implementing the videocapture.py module. But thats another story. Either of the 2 mentioned scripts, draw_pic and testgui, would work for me if I can find a way to use either .bmp or .jpg(preferred) and also let me use 320x240 pixels. I even have a loosly translated tute on french blender site about the draw_pic script. It is missing much of the basics I need to understand how it works.

:-?