hello peeps.
Im having a bit of trouble when drawing to a texture during runtime.
I figured out I need to draw my stuff to the backbuffer first, then copy it to an existing OpenGL texture. This is no problem in itself, but the problem arises during the drawing to the backbuffer. There is no actual Flip()/swapbuffer command issued during the texture drawing, and the actual drawing of the scene in the main loop occurs later on in the code, so there is a glCear()/Cls() issued later in the code. But for some reason, the stuff I draw still apears on the screen, but just for a split second it's visible before being replaced by the actual scene.
Why is this happening?
here is the routine I use for drawing to the texture.
the t.Draw( x, y ); routine is simple:
This is not the only instance where I can actually see the backbuffer contents on my screen without it having been 'flipped'. Other parts of the code where I attempted drawing to a texture had a similar result.
Note that I have tried various different things to make it go away. Like insert a CLS() at the end of the drawing routine. This does stop the drawn contents from showing on my screen, but instead it shows a completely black background for a split second.
Either a backbuffer does not exist and everything is just drawn to the frontbuffer directly, or for some reason, either Max2D or OpenGL insists on swapping the front/back buffer without issuing an explicit Flip/SwapBuffer
Im having a bit of trouble when drawing to a texture during runtime.
I figured out I need to draw my stuff to the backbuffer first, then copy it to an existing OpenGL texture. This is no problem in itself, but the problem arises during the drawing to the backbuffer. There is no actual Flip()/swapbuffer command issued during the texture drawing, and the actual drawing of the scene in the main loop occurs later on in the code, so there is a glCear()/Cls() issued later in the code. But for some reason, the stuff I draw still apears on the screen, but just for a split second it's visible before being replaced by the actual scene.
Why is this happening?
here is the routine I use for drawing to the texture.
Method UpdateTexture() If( Lines.Length = 0 ) Then Return; End If '// are we in Render or Select mode? '// (Select mode is used by Entity.__getPicked() routine) Local rm:Int; glGetIntegerv( GL_RENDER_MODE, Varptr rm ); If( rm <> GL_RENDER ) Then Return; '// If( AsciiTables = Null ) Then '// GenerateAsciiTables(); '// End If If( (Texture[0] = Null) Or ((Texture[0].Width <> (Size.x * 2)) Or (Texture[0].Height <> (Size.y * 2))) ) Then Local img:TImage = CreateImage( Size.x * 2, Size.y * 2 ); Texture[0] = GLTexture.FromImage( img ); End If SetAlpha( 1 ); TileImage( Texture[1].Image ); Local x:Float = 2.0; Local y:Float = 2.0; Local maxlines:Int = Texture[0].Height / TextHeight( "M" ); Local startline:Int = 0; If( maxlines < Lines.Length - 1 ) Then startline = (Lines.Length - 1) - maxlines; End If For Local l:TBLine = EachIn Lines If( l.Position >= startline ) Then For Local w:TBWord = EachIn l.Words For Local t:TBToken = EachIn w.Tokens t.Draw( x, y ); x :+ TextWidth( Chr(t.Value) ); Next x :+ TextWidth(" "); Next y :+ TextHeight( " " ); x = 2.0; End If Next glCopyTexSubImage2D ( .. Texture[0].Texture.ID, .. '// target 0, .. '// level 0, 0, .. '// xoffset, yoffset 0, Stage.Instance.StageHeight - Texture[0].Height, .. '// x , y Texture[0].Width, Texture[0].Height.. '// width, height ); oldText = Text; End Method
the t.Draw( x, y ); routine is simple:
Method Draw( lx:Float = -1, ly:Float = -1 ) If( lx = -1 ) Then lx = x; If( ly = -1 ) Then ly = y; If( IsSelected ) Then SetColor( 255-Word.Textbox.ForeColor[0], 255-Word.Textbox.ForeColor[1], 255-Word.Textbox.ForeColor[2] ); Else SetColor( Word.Textbox.ForeColor[0], Word.Textbox.ForeColor[1], Word.Textbox.ForeColor[2] ); End If DrawText( Chr(Value), lx, ly ); End Method
This is not the only instance where I can actually see the backbuffer contents on my screen without it having been 'flipped'. Other parts of the code where I attempted drawing to a texture had a similar result.
Note that I have tried various different things to make it go away. Like insert a CLS() at the end of the drawing routine. This does stop the drawn contents from showing on my screen, but instead it shows a completely black background for a split second.
Either a backbuffer does not exist and everything is just drawn to the frontbuffer directly, or for some reason, either Max2D or OpenGL insists on swapping the front/back buffer without issuing an explicit Flip/SwapBuffer
