help for writepixel in texture!!

BlitzMax Forums/MiniB3D Module/help for writepixel in texture!!

mongia2(Posted 2007) [#1]
it is a code for opengl

Function TextureWrite(tt:ttexture , xx:Int , yy:Int , col:Int)

Local map:tpixmap = tt.pixmap
Local w:Int = map.width
Local h:Int = map.height
Local x:Int , y:Int
Local pxl:Int

If map.format<>PF_RGBA8888
map = map.Convert(PF_RGBA8888)
Print "Convert"
EndIf


WritePixel map , xx , yy , col
'glDeleteTextures 1 , Varptr tt.gltex[0]
Local nuova_texture
glGenTextures 1,Varptr nuova_texture
tt.gltex[0] = nuova_texture

glBindtexture GL_TEXTURE_2D , tt.gltex[0]
glPixelStorei GL_UNPACK_ROW_LENGTH,map.pitch/BytesPerPixel[map.format]
glTexImage2D GL_TEXTURE_2D,0,GL_RGBA8,tt.width,tt.height,0,GL_RGBA,GL_UNSIGNED_BYTE,map.pixels


End Function


help mee!!


my example


Import klepto.minib3d

'SuperStrict


Global surf:tsurface
Global mesh:tmesh
Global tria:Int

Global pix:Int[256,256]


Graphics3D 640,480,0,2
ClearTextureFilters()


Global camera:tcamera = CreateCamera()
PositionEntity camera,0,0,0

Global box:tentity = CreateCube()
PositionEntity box,1,0,3
ScaleEntity box,1,1,.2
RotateEntity box,0,40,0
EntityPickMode box,2


Global box2:tentity = CreateCube()
ScaleEntity box2,.02,.02,.02
EntityColor box2,255,0,0



For nx = 0 To 255
For ny = 0 To 255

pix(nx , ny) = Rnd(65000)

Next
Next


While Not KeyDown(key_escape)

Local x#,y#,z#

TurnEntity box,KeyDown(key_up)-KeyDown(key_down),0,0




ent=CameraPick(camera,MouseX(),MouseY())

If ent>0

x# = PickedX()+(PickedNX()*0.01)
y# = PickedY()+(PickedNY()*0.01)
z# = PickedZ()+(PickedNZ()*0.01)
PositionEntity box2,x#,y#,z#



End If




te=MilliSecs()
salva_texture()
te2=MilliSecs()-te


RenderWorld


TGlobal.BeginMax2D

SetBlend AlphaBlend
SetAlpha 1


DrawText te2,10,10


TGlobal.EndMax2D




Flip

Wend

End


Function salva_texture()


Local image:TPixmap = CreatePixmap:TPixmap(256,256,PF_RGB888)
For Local nx:Int = 0 To 255
For Local ny:Int = 0 To 255
WritePixel(image , nx , ny ,pix(nx , ny))
Next
Next

SavePixmapPNG( image:TPixmap,"salva_immagine.png")

EntityTexture box,LoadTexture:ttexture("salva_immagine.png")
EntityFX box,32+3


image = Null




End Function


mongia2(Posted 2007) [#2]
my method for manipolation ioff texturee:

i create a pixmap
and save pixmap and load a texture!
but it is slowwwww




box=createcube()
Global image:TPixmap = CreatePixmap:TPixmap(256,256,PF_RGBA8888) ' with alpha

Function manipolation_texture()

Local nx:Int,ny:Int



For nx= 0 To 255

For ny= 0 To 255

WritePixel(image , nx , ny ,rnd(65000))

Next

Next

SavePixmapPNG( image,"salva_immagine.png")

EntityTexture box,LoadTexture:ttexture("salva_immagine.png")

End Function