Minib3d openGL texture mapping?
BlitzMax Forums/MiniB3D Module/Minib3d openGL texture mapping?
| ||
| I'm trying to map a texture to a triangle and am having an extremely difficult time, It seems like I have to "Re-Generate" the texture every time I want to use it. http://infotread.com/downloads/Main.debug.zip --Code (Included in Zip file) Main.bmx
SuperStrict
Import SiDesign.minib3d
Include "ParticleSystem.bmx"
AppTitle = "Particle Test"
Graphics3d(800,600,0,2)
Global Camera:TCamera = CreateCamera()
'CameraClsMode camera,False,False
Global Light:TLight = CreateLight()
Global Ground:TMesh = CreateCube()
Global GroundTexture:TTexture = LoadTexture("snow.jpg")
Global t_FPS:Int
Global t_counter:Int
Global t_second:Int = MilliSecs()
Initialize()
'Create Particle Manager
Global ParticleManager:TParticleManager = New TParticleManager
'Create Fire Particle System
Global FireParticleSystem:TParticleSystem = ParticleManager.CreateParticleSystem()
FireParticleSystem.TextureImage = LoadPixmap("fire1.png")
'FireParticleSystem.TextureImage = LoadPixmap("NeHe.bmp")
'FireParticleSystem.TextureImage = LoadPixmap("fire.bmp")
FireParticleSystem.ParticleLife = 2000
FireParticleSystem.SystemRate = 100
FireParticleSystem.SystemVolume = 1
FireParticleSystem.Initialize()
FireParticleSystem.Execute(0,1,0)
'Create Smoke Particle System
'Global SmokeParticleSystem:TParticleSystem = ParticleManager.CreateParticleSystem()
'SmokeParticleSystem.TextureImage = LoadPixmap("smoke1.png")
'SmokeParticlesystem.Initialize()
'SmokeParticleSystem.Execute(0,1,0)
'hideentity(Ground)
While Not KeyHit(KEY_ESCAPE)
Update()
Renderworld
'Update Particles
ParticleManager.Update()
BeginMax2d()
Draw()
EndMax2d()
Flip
Cls
Wend
Function Update()
If KeyDown(KEY_LEFT)
MoveEntity(Camera,-0.3,0,0)
'PointEntity(Camera,Ground)
EndIf
If KeyDown(KEY_RIGHT)
MoveEntity(Camera,0.3,0,0)
'PointEntity(Camera,Ground)
EndIf
If KeyDown(KEY_UP)
TranslateEntity(Camera,0,0.3,0)
'PointEntity(Camera,Ground)
EndIf
If KeyDown(KEY_DOWN)
TranslateEntity(Camera,0,-0.3,0)
'PointEntity(Camera,Ground)
EndIf
If KeyDown(KEY_P) Then PointEntity(Camera,Ground)
If KeyDown(KEY_NUMADD) Then MoveEntity(Camera,0,0,0.3)
If KeyDown(KEY_NUMSUBTRACT) Then MoveEntity(Camera,0,0,-0.3)
If KeyDown(KEY_SPACE)
FireParticleSystem.Execute(0,1,0)
'SmokeParticleSystem.Execute(0,1,0)
EndIf
End Function
Function Draw()
t_counter = t_counter + 1
If MilliSecs() > t_second + 1000
t_second = MilliSecs()
t_FPS = t_counter
t_counter = 0
End If
DrawText "FPS: " + t_FPS, GraphicsWidth() - 100, 0
DrawText "Memory: " + GCMemAlloced(),0,0
End Function
Function Initialize()
ScaleEntity(Ground,100,0.1,100)
EntityTexture(Ground,GroundTexture)
ScaleTexture(GroundTexture,-0.1,-0.1)
PositionEntity(Camera,0,7,-7)
PointEntity(Camera,Ground)
PositionEntity(Light,100,100,-100)
PointEntity(Light,Ground)
End Function
--Particles Global t_rot:Float = 0.0 Type TParticleManager 'Particle Systems Field ParticleSystemInstances:TList = CreateList() Method New() glewInit() End Method Method Update() For Local SystemInstance:TParticleSystemInstance = EachIn ParticleSystemInstances SystemInstance.Update() Next End Method Method CreateParticleSystem:TParticleSystem() Local System:TParticleSystem = New TParticleSystem System.ParticleManager = Self Return System End Method End Type Type TParticleSystem 'Particle Manager Field ParticleManager:TParticleManager 'Texture Image Field TextureImage:TPixmap Field Texname:Int Field Checkimage:Byte[256,256,4] 'System Properties Field SystemRate:Int Field SystemVolume:Int 'Particle Properties Field ParticleLife:Int Method Initialize() glGenTextures(1, Varptr Texname) ' Create One Texture glBindTexture(GL_TEXTURE_2D, Texname) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 4, TextureImage.width, TextureImage.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureImage.pixels) glEnable(GL_TEXTURE_2D) ' Enable Texture Mapping glShadeModel(GL_SMOOTH) ' Enable Smooth Shading glClearColor(0.0, 0.0, 0.0, 0.0) ' Black Background glClearDepth(1.0) ' Depth Buffer Setup glDisable(GL_DEPTH_TEST) ' Disable Depth Testing glEnable(GL_BLEND) ' Enable Blending glBlendFunc(GL_SRC_ALPHA,GL_ONE) ' Type Of Blending To Perform glDepthFunc(GL_LEQUAL) ' The Type Of Depth Testing To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) ' Really Nice Perspective Calculations glHint(GL_POINT_SMOOTH_HINT,GL_NICEST) ' Really Nice Point Smoothing glBindTexture(GL_TEXTURE_2D,Texname) ' Select Our Texture glMatrixMode(GL_MODELVIEW) End Method Method Execute(x:Float,y:Float,z:Float) Local SystemInstance:TParticleSystemInstance = New TParticleSystemInstance SystemInstance.System = Self SystemInstance.x = x SystemInstance.y = y SystemInstance.z = z ParticleManager.ParticleSystemInstances.AddLast(SystemInstance) End Method End Type Type TParticleSystemInstance 'System Field System:TParticleSystem 'Time Field LastUpdate:Int 'Particles Field Particles:TList = CreateList() 'Position Field x:Float Field y:Float Field z:Float Method Update() ' If MilliSecs() >= LastUpdate + System.SystemRate ' LastUpdate = MilliSecs() glMatrixMode(GL_MODELVIEW) glDisable(GL_LIGHTING) Local modelView:Float[16] glPushMatrix glGetFloatv(GL_MODELVIEW_MATRIX,modelView) For Local i:Int = 0 To 2 For Local j:Int = 0 To 2 If i = j modelview[i*4+j] = 1.0 Else modelview[i*4+j] = 0.0 EndIf Next Next glLoadMatrixf(modelView) glEnable(GL_TEXTURE_2D) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) glBindTexture GL_TEXTURE_2D,Self.System.Texname glColor3f 0.0, 0.0, 1.0 glBegin(GL_TRIANGLE_STRIP) ' Build Quad From A Triangle Strip glTexCoord2f(1,1); glVertex3f(x+0.5,y+0.5,z) ' Top Right glTexCoord2f(0,1); glVertex3f(x-0.5,y+0.5,z) ' Top Left glTexCoord2f(1,0); glVertex3f(x+0.5,y-0.5,z) ' Bottom Right glTexCoord2f(0,0); glVertex3f(x-0.5,y-0.5,z) ' Bottom Left glEnd() glPopMatrix End Method End Type Type TParticle 'System Instance Field SystemInstance:TParticleSystemInstance 'Position Field x:Float Field y:Float Field z:Float 'Size Field size:Float 'Velocity Field vx:Float Field vy:Float Field vz:Float 'Gravity Field gx:Float Field gy:Float Field gz:Float 'Color Field cr:Float Field cg:Float Field cb:Float Method Update() End Method End Type Last edited 2012 |
| ||
| Solved, Apparently I have to call glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Self.System.TextureImage.Width, Self.System.TextureImage.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Self.System.TextureImage.Pixels) before I create my polygons |