def allocate(): if _depth>1 : image = osg.Image() image.allocateImage(_width, _height, _depth, GL_RGBA, GL_UNSIGNED_BYTE) texture = osg.Texture3D() texture.setImage(image) texture.setResizeNonPowerOfTwoHint(False) return StateAttributeObject(texture) if _height>1 : image = osg.Image() image.allocateImage(_width, _height, 1, GL_RGBA, GL_UNSIGNED_BYTE) texture = osg.Texture2D() texture.setImage(image) texture.setResizeNonPowerOfTwoHint(False) return StateAttributeObject(texture) if _width>1 : image = osg.Image() image.allocateImage(_width, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE) texture = osg.Texture1D() texture.setImage(image) texture.setResizeNonPowerOfTwoHint(False) return StateAttributeObject(texture) else: throw "Invalid texture size of 0,0,0"
class Heatmap (osg.Geode) : Heatmap(float width, float depth, float maxheight, unsigned int K, unsigned int N, float maximum, float transparency) ~Heatmap() setData = void(float *buffer, float maxheight, float maximum, float transparency) m_K = unsigned int() m_N = unsigned int() *m_data = float() m_img2 = osg.Image() m_tex2 = osg.Texture2D() colorimg = osg.Image() colortex = osg.Texture1D() *maximumUniform = osg.Uniform() *maxheightUniform = osg.Uniform() *transparencyUniform = osg.Uniform()
4, GL_RGBA, GL_UNSIGNED_BYTE, unsigned char[4 * texSize], osg.Image.USE_NEW_DELETE)() ptr = image.data() inc = 2. * PI / (float)texSize for(int i = 0 i < texSize i++) *ptr++ = (GLubyte)((sinf(i * inc) * 0.5 + 0.5) * 255.) *ptr++ = 0 *ptr++ = 0 *ptr++ = 1 return image static osg.Texture1D* make1DSineTexture( int texSize ) sineTexture = osg.Texture1D() sineTexture.setWrap(osg.Texture1D.WRAP_S, osg.Texture1D.REPEAT) sineTexture.setFilter(osg.Texture1D.MIN_FILTER, osg.Texture1D.LINEAR) sineTexture.setFilter(osg.Texture1D.MAG_FILTER, osg.Texture1D.LINEAR) sineTexture.setImage( make1DSineImage(texSize) ) return sineTexture #####################################/ # in-line GLSL source code for the "microshader" example static char *microshaderVertSource = "# microshader - colors a fragment based on its position\n" "varying vec4 color\n" "void main(void)\n" "\n" " color = gl_Vertex\n"
program.setName( "mesh" ) program.addBindAttribLocation("xypos", 6) program.addShader( osg.Shader( osg.Shader.VERTEX, VertexShader ) ) program.addShader( osg.Shader( osg.Shader.FRAGMENT, DepthPeeling.PeelingShader ) ) program.addShader( osg.Shader( osg.Shader.FRAGMENT, FragmentShader ) ) # create a 1D texture for color lookups colorimg = osg.Image() colorimg.allocateImage(5, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE) data = colorimg.data() *data++ = 0 *data++ = 0 *data++ = 255 *data++ = 0 # fully transparent blue *data++ = 0 *data++ = 255 *data++ = 255 *data++ = 255 # turquoise *data++ = 0 *data++ = 255 *data++ = 0 *data++ = 255 # green *data++ = 255 *data++ = 255 *data++ = 0 *data++ = 255 # yellow *data++ = 255 *data++ = 0 *data++ = 0 *data++ = 255 # red colortex = osg.Texture1D(colorimg) colortex.setFilter(osg.Texture.MIN_FILTER, osg.Texture.LINEAR) colortex.setFilter(osg.Texture.MAG_FILTER, osg.Texture.LINEAR) colortex.setWrap(osg.Texture.WRAP_S, osg.Texture.CLAMP_TO_EDGE) colortex.setResizeNonPowerOfTwoHint(False) # create a 2D texture for data lookups m_img2 = osg.Image() m_img2.allocateImage(K, N, 1, GL_LUMINANCE, GL_FLOAT) m_img2.setInternalTextureFormat(GL_RGB32F_ARB) m_data = (float*)m_img2.data() m_tex2 = osg.Texture2D(m_img2) m_tex2.setResizeNonPowerOfTwoHint(False) m_tex2.setFilter(osg.Texture.MIN_FILTER, osg.Texture.LINEAR) m_tex2.setFilter(osg.Texture.MAG_FILTER, osg.Texture.LINEAR) m_tex2.setWrap(osg.Texture.WRAP_S, osg.Texture.CLAMP_TO_EDGE)
nobands = colorbands.size() delta = nobands/(float)noPixels pos = 0.0 # fill in the image data. dataPtr = (osg.Vec4*)image.data() for(int i=0i<noPixels++i,pos+=delta) #float p = floorf(pos) #float r = pos-p #osg.Vec4 color = colorbands[(int)p]*(1.0-r) #if p+1<colorbands.size() : color += colorbands[(int)p+1]*r color = colorbands[(int)pos] *dataPtr++ = color texture = osg.Texture1D() texture.setWrap(osg.Texture1D.WRAP_S,osg.Texture1D.MIRROR) texture.setFilter(osg.Texture1D.MIN_FILTER,osg.Texture1D.LINEAR) texture.setImage(image) material = osg.Material() stateset = osg.StateSet() stateset.setTextureAttribute(0,texture,osg.StateAttribute.OVERRIDE) stateset.setTextureMode(0,GL_TEXTURE_1D,osg.StateAttribute.ON|osg.StateAttribute.OVERRIDE) stateset.setTextureMode(0,GL_TEXTURE_2D,osg.StateAttribute.OFF|osg.StateAttribute.OVERRIDE) stateset.setTextureMode(0,GL_TEXTURE_3D,osg.StateAttribute.OFF|osg.StateAttribute.OVERRIDE) stateset.setTextureMode(0,GL_TEXTURE_GEN_S,osg.StateAttribute.ON|osg.StateAttribute.OVERRIDE)