How do you save the opengl drawing that is generated from a python script. What commands are there to do this? The code I have below draws four parabolas and then data from a file. Is there a way to separate the original drawing of the parabolas and background color from the section that reads from the file? Really what I am wanting is to draw the parabolas to the screen only once (since only a small part of the screen will change when the data file is read). Then I want the screen to update everytime the data file is changed. What do I need to do to the structure of the code below to accomplish this?
import math
import Blender
from Blender.BGL import *
from Blender import Draw
R = G = B = 1.0
A = 1
title = "Testing BGL + Draw"
instructions = "Use mouse buttons or wheel to change the background color."
quitting = " Press ESC or q to quit."
len1 = Draw.GetStringWidth(title)
len2 = Draw.GetStringWidth(instructions + quitting)
#
def show_win():
glClearColor(R,G,B,A) # define color used to clear buffers
glClear(GL_COLOR_BUFFER_BIT) # use it to clear the color buffer
glColor3f(0,0,0) # define default color
for i in range(1000):
for j in range(1000):
y1 = (((i-500)**2)/(-150.0)) + 700
y2 = (((i-500)**2)/(-300.0)) + 850
if i<500:
y5 = 200*math.cos(6.28318530781*(i+150)/500)+200
else:
y5 = 200*math.sin(6.28318530781*(i-25)/500)+200
if ((j<y1 and j>y2) or (j > y1 and j <y2))and j>y5:
glBegin(GL_POLYGON)
glVertex2f(i/2.0-0.25, j/2.0-.25)
glVertex2f(i/2.0-0.25, j/2.0+.25)
glVertex2f(i/2.0+0.25, j/2.0+.25)
glVertex2f(i/2.0+0.25, j/2.0-.25)
glEnd()
glColor3f(.5,.5,.5)
for i in range(1000):
for j in range(1000):
y3 = (((i-500)**2)/(-200.0)) + 750
y4 = (((i-500)**2)/(-250.0)) + 800
if i<500:
y6 = 200*math.cos(6.28318530781*(i+150)/500)+225
else:
y6 = 200*math.sin(6.28318530781*(i-25)/500)+225
if ((j<y3 and j>y4) or (j>y3 and j<y4)) and j>y6:
glBegin(GL_POLYGON)
glVertex2f(i/2.0-0.25, j/2.0-0.25)
glVertex2f(i/2.0-0.25, j/2.0+0.25)
glVertex2f(i/2.0+0.25, j/2.0+0.25)
glVertex2f(i/2.0+0.25, j/2.0-0.25)
glEnd()
f=file('c:\documents and settings\user\desktop\cppdata.txt','r')
f.seek(0)
str=f.readline()
temp=str.split()
numberdata=float(temp[0])
str=f.readline()
temp=str.split()
popmax=float(temp[0])
for i in range(numberdata):
str=f.readline()
temp=str.split()
x=float(temp[0])
y=float(temp[1])
pop=float(temp[2])
shade=(pop/(4*popmax)+0.75)
glColor3f(shade, shade, shade)
glBegin(GL_POLYGON)
glVertex2f(x/2.0-0.25, y/2.0-0.25)
glVertex2f(x/2.0-0.25, y/2.0+0.25)
glVertex2f(x/2.0+0.25, y/2.0+0.25)
glVertex2f(x/2.0+0.25, y/2.0-0.25)
glEnd()
def ev(evt, val): # event callback for Draw.Register()
global R,G,B,A # ... it handles input events
if evt == Draw.ESCKEY or evt == Draw.QKEY:
Draw.Exit() # this quits the script
Draw.Register(show_win, ev, None) # start the main loop