Don't Tread On Me

BlitzMax Forums/BlitzMax Beginners Area/Don't Tread On Me

dw817(Posted 2016) [#1]
I'm beginning to believe that the normal graphics BlitzMAX comes with is not at all happy working with GL graphic commands, and that they fight each other. Try out this code to see what I mean:
Strict
SetGraphicsDriver(GLMax2DDriver())
Graphics 640,480

Repeat
  Cls
  If KeyDown(32) Then DrawText "SPACE",0,0
'  DrawRect 0,0,0,0 ' UNREM me to work
  If KeyDown(65) Then
    drawhollowoval 0,0,200,100
    drawhollowoval 25,25,200,100
  EndIf
  Flip
Until KeyDown(27)

Function drawhollowoval(h,v,x,y)
  glbegin(gl_line_loop)
  _max2ddriver.DrawOval h,v,h+x,v+y,h,v
  glend
End Function
Run this, now hit A. NOTICE, we have two nice HOLLOW ovals, not a normal function of BlitzMAX.

Now hit SPACE, text appears, now hit A again, and it WON'T APPEAR anymore ! It's getting tread on.

Definitely something screwy going on here - and once again it's probably an amateur question for you aces out there. :)

So what is happening and what code can I use to correct this (outside of plotting a dummy rectangle or other drawing element) so the oval will display alongside normal graphic functions like drawtext() ?

If this can be solved, it could mean the end of complex code building hollow circles, ovals, rectangles, and polygons.


BlitzMan(Posted 2016) [#2]
Is it GLDrawText,not DrawText.You are using GL.Not DirectX


col(Posted 2016) [#3]
It may because inside the _mad2ddriver.DrawOval there is a glbegin/glend pair for setting the state to draw GL_POLYGONS. There are only certain commands allowed between a glbegin/glend pair and having nested glbegin/glend is invalid and the commands will be ignored hence you're not seeing anything.


col(Posted 2016) [#4]
You could copy the guts of the gl version of the DrawOval into your drawhollowoval function and set the state to gl_line_loop. Alternatively, and much cleaner in my opinion would be to have another parameter for the basic 2d functions that can be used as fill/hollow flag - alas that would mean making module tweaks.


BlitzMan(Posted 2016) [#5]
.


dw817(Posted 2016) [#6]
Dave:

Curiously, just adding a drawrect() before the oval does the trick. It's only when I use DrawText() and no drawrect() does it boff up. If I call DrawRect() after - even if it doesn't plot anything, that still fixes it.

It's too convenient to have a hollow rectangle like this to disdain the small code completely. For now, I can use a dummy DrawRect before plotting, that will fix it.

Dave, where can I find the GL version source ? Or ... do I need to compile something ?

It's a little too easy to draw a hollow rectangle with just lines, so, likely that might be all that was needed as far as elements desired, a hollow oval, that was not originally part of BlitzMAX.
Strict
SetGraphicsDriver(GLMax2DDriver())
Graphics 640,480

Repeat
  Cls
  If KeyDown(32) Then DrawText "SPACE",0,0
  If KeyDown(65) Then
    drawhollowoval 0,0,200,100
    drawhollowoval 25,25,200,100
  EndIf
  Flip
Until KeyDown(27)

Function drawhollowoval(h,v,x,y)
  DrawRect 0,0,0,0 ' this fixes it
  glbegin(gl_line_loop)
  _max2ddriver.DrawOval h,v,h+x,v+y,h,v
  glend
End Function
Blitzman, really - all graphic libraries should play nice and not try to outdo each other by clearing the screen first just because some mode isn't set.


col(Posted 2016) [#7]
Ahh I see what you mean.
That is a bit wierd. I don't know what's going on there then :/ other than hazarding a wild guess that its setting a gpu/driver state and that gpu/driver state is persisting over several commands, it is wierd though I agree. The info for the gBegin/glEnd pair is in the OpenGL spec.

The source for all of BlitzMax is in your <blitzmax installation folder>/mod/ folder.
The glmax2ddriver source is in /mod/brl.mod/glmax2d.mod/glmax2d.bmx.

If you wanted to, then you can place a DebugStop command before any commands and use the debugger to step into the functions. You'll need to have 'Program Menu->Build Options->Debug Build' ticked to create an exe with Debug information and for the DebugStop command to stop execution. Changes in any of the module sources won't take until you 'Build Modules' - that process was already mentioned in another post.


dw817(Posted 2016) [#8]
Morning, Dave.

Well I see what this is showing me is that it's entirely possible to mix GL graphic commands with normal ones.

I know there are some impressive 3D demos written in BlitzMAX, I just need to take a look at them now and see if I can get them to function with normal commands of grabimage(), readpixel(), and writepixel().

Thanks for the info !