drawing on bge.texture.Texture source enables MIPMAP?

I am trying to draw a procedural image but it results in blurred image.

from bge.texture import ImageBuff,Texture,materialID, ImageFFmpegfrom bge import logic 
from random import randint
import array


from bge import render
render.setMipmapping(render.RAS_MIPMAP_NONE)


scene = logic.getCurrentScene()
cont = logic.getCurrentController()
own = cont.owner


SIZE = 2 ** 6
   
def generatePattern(source, width, height):
    pattern_buffer = array.array('B')
    for y in range(height):
        for x in range(width):
            r,g,b = (randint(0,255) for i in range(3))
            pattern_buffer.append(r)
            pattern_buffer.append(g)
            pattern_buffer.append(b)
    source.load(pattern_buffer, width, height)
    return source


def main():
    if cont.sensors['Keyboard'].positive:
        obj = scene.addObject('Plane',own)
        obj.worldPosition = own.worldPosition


        if not "texture" in obj:  
            for matID in range(len(obj.meshes[0].materials)):  
                renderToTexture = Texture(obj, matID)    
                renderToTexture.source = generatePattern(ImageBuff(),SIZE,SIZE)
                # renderToTexture.mipmap = False
                renderToTexture.refresh(True)
                obj["texture"] = renderToTexture


main()

This is weird as the other textures in the scene (that are not edited) stay sharp.
Also, apparently ‘renderToTexture.mipmap = False’ does nothing in this case.

Attachments

broken.blend (498 KB)

Hi, http://www.pasteall.org/blend/42690. you can also have a look at these threads if you are interested:

Thanks, this works!

Really important/urgent question:

How can I achieve this also in MULTITEXTURE mode?

(what I want to demo http://i.imgur.com/EH6I6oC.png , voxels, mutlitex gives additional 2x performance but looks like ass)

I don’t know multitexture, we removed it in upbge… I thought that multitexture didn’t support GLSL but worked with openGL…

So I tried this code:


from bgl import *
import bge
from random import uniform
from itertools import chain


cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner


if not hasattr(bge, "pixels"):
    pixels = []
    for i in range(1024):
        for j in range(1024):
            r = uniform(0, 1)
            g = uniform(0, 1)
            b = uniform(0, 1)
            pixels.append((r, g, b))
            
    bge.pixels = list(chain(*pixels))
    
def draw():        
    imbuf = Buffer(GL_FLOAT, [1024*1024*3], bge.pixels)


    mat = own.meshes[0].materials[0]
    bindcode = mat.getTextureBindcode(0)


    glBindTexture(GL_TEXTURE_2D, bindcode)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 1024, 0, GL_RGB, GL_FLOAT, imbuf)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    
draw()

that is pure openGL and it works only in GLSL mode so I don’t know what’s wrong. I tried with scene.post_draw, scene.pre_draw and it doesn’t work…

EDIT: with your .blend I don’t know why but I can’t see anything rendered in multitexture (blender 2.77a)

Woa, nice code example, really like it :slight_smile:
I even got alpha working somehow

The not drawing was because


was missing

Attachments

broken_in_multitexture.blend (496 KB)

If you want that alpha also works for GLSL mode, you have to enable Z-Transparency in the material.

Cool that your problem is solved :)*

EDIT: pqftgs told me a faster way than itertools.chain … I have to find it. I think it was bge.pixels = list(chain.from_iterable(pixels))

EDIT2: As my code snippet didn’t worked in multitexture I tried several things and I replaced glTexParamateri with glTexParamaterf… I don’t know exactly what it means but normally I use glTextParamereri.

It works for this example and one of my computers.
But considering the abuse I am doing do blender, I guess i can’t ask for too much.
(lib load is magic)

I will open an another thread on what I am actually doing before I investigate this further.

So its a something I guess… :spin::spin::spin::spin::spin: