How do you do 2D drawing in BMAX and OGL?

BlitzMax Forums/BlitzMax OpenGL Programming/How do you do 2D drawing in BMAX and OGL?

I have no idea where to start when it comes to drawing and plotting in 2D with OpenGL. I can open and setup a graphics window, as per the numerous excellent tutorials and examples on OpenGL with 3D stuff.

I'd like to know how to being and do this, as I have many things I'd like to try and do (mainly special effects) and see if they are any faster then using WritePixel and Pixel Maps. As I was under the impression that with BMAX everything was going to be much much quicker then previous flavours.

If you could help get me started with this, then that would be magic. One of the pitfulls I am gonig to get really perplexed over is converting Alpha. Red, Green and Blue colours into converting with open GL ones 0.0 - 1.0.

I take it I'd need to have an array of somekind to store image infromation, etc.

This is how Im currently doing things with WPF. And would like very much to do with OpenGL, to see if it is quicker. It's the main reason I bought BMAX. As im finding MAX2D very slow at doing effects.
' Write Pixel and LockImage drawing.
' bu Thumbz 2005

' for this example greyscale filtered.

Strict


' Screen setup.
Const XRES=640
Const YRES=480

Graphics XRES,YRES
HideMouse


Local ImageFile$="media/insertimagenamehere.png" 		' any size image you like upto the screen res.

Global Image=LoadImage(ImageFile$,DynamicImage)		' the main image to be used for manipulating.

Global IW=ImageWidth (Image) 
Global IH=ImageHeight(Image) 

Global Blank=CreateImage(XRES,YRES)

Global Locked:TPixmap

Global RGB[IW,IH]
	
	
	' read and store colour information. 
	Locked=LockImage(Image)

	For Local x=0 To IW-1
		For Local y=0 To IH-1
			
			RGB[x,y]=ReadPixel(Locked,x,y)
			
		Next
	Next

	UnlockImage(Image)




' main loop.
While Not KeyHit(KEY_ESCAPE)
	
	
	' Update the image and redraw.
	
	UpdateImage()

	DrawImage Blank,0,0

	FlushMem
	
Flip
Cls
Wend 

EndGraphics 

Function UpdateImage()
		
	Local Alp
	Local Red 
	Local Grn 
	Local Blu
	Local Col 
	Local x,y
	
	Local average
	
	Locked=LockImage(Blank)

	
	' Apply new settings.
	
	For y=0 To IH-1
		For x=0 To IW-1

			' get colour info
			
			col	= rgb [ x, y ]
			
			alp	= (col Shr 24) & 255
			Red 	= (col Shr 16) & 255
			Grn 	= (col Shr  8) & 255
			blu 	= (col Shr  0) & 255
			
			' the new colour settings.
			
			Average=(Red | Grn | Blu) / 3		
			
			Red=Average
			Blu=Average
			Grn=Average
			
			' Colour Limits.
			
			If Red<000 Then Red=000
			If Red>255 Then Red=255
			
			If Grn<000 Then Grn=000
			If Grn>255 Then Grn=255
			
			If Blu<000 Then Blu=000
			If Blu>255 Then Blu=255
			
			col	= (alp Shl 24) | (red Shl 16) | (grn Shl 8) | (blu Shl 0)
             	
			' write pixel draw	
			
			If col<>000000
				WritePixel (Locked,x,y,col)
			End If
		
		Next
	Next
	
	UnlockImage(Blank)

End Function




Hugest of thanks,
THUMBZ

After reading your post twice, I have determined that I am unable to figure out what it is you're asking.

How to Do drawing using OpenGL, in 2D rather than 3D.
And also manipulate colours for effects etc.

Must appologize, as im very tired when I wrote it.

Instead of going into an elaborate explanation stating that it's doable but not fast or a good idea, I'll just tell you that you can't do it.

Really, though, it's not a good idea to be trying to do 'true' 2D stuff with OpenGL last I checked.

Well actually it's easy. You'd just have to setup the Projection matrix with an orthographical view. To do this, use:
glMatrixMode GL_PROJECTION
glLoadIdentity
gluOrtho2D(0, GRAPHICSWIDTH, GRAPHICSHEIGHT, 0)
glMatrixMode GL_MODELVIEW
glLoadIdentity
glDisable GL_DEPTH_TEST 'you may want to disable depth testing so you can define the render order exactly

After having set the matrices you can draw any primitve directly to the screen coordinates using glBegin, glEnd and glVertex2f with screen coordinates. A little example:
glBegin GL_LINES
glVertex2f X1#, Y1# 'draws a line from P1 to P2
glVertex2f X2#, Y2# 'note that these coords are screen coords
glEnd

You can use many primitives with glBegin, just search for pictures with "gl primitives" in Google and it will show you some. And have a look into the Redbook for explanations of how to use them.

And by the way, if you have any more OpenGL regarding questions, could you post them all in one of your threads?

@NC:
Instead of going into an elaborate explanation stating that it's doable but not fast or a good idea, I'll just tell you that you can't do it.

Really, though, it's not a good idea to be trying to do 'true' 2D stuff with OpenGL last I checked.

Whys that, seeing as MAX2D uses OpenGL to draw with?

---------------------------------------------------------

I knew this would stumble me, any ideas on how to convert RGB values into readable OpenGL ones?

Normal RGB 255 colour ranges, and HEX $000000 - $ FFFFFF. Would be terrific.


Thanks for the help,
THUMBZ

can you not do this:

OpenglRed:float = 1.0 / (255.0 * red)
OpenglGreen:float = 1.0 / (255.0 *green)
OpenglBlue:float = 1.0 / (255.0 * blue)


This would do things in a 'component' wise order but it should work?

[EDITED] You should use RndFloat() for random numbers between 0.0 and 1.0. You should also change the SeedRnd value everytime your code is run or the random number generator commands will generate the same value. ie at the top of your code use

SeedRnd Millisecs() 'Generate a random seed based on Millisecs (which is always changing)


I'll give it a bash. Thanks Colonel.

Thanks Col!

Here's my progress so far:
'
' OPENGL 2D Drawing Test Example
'

Const XRES=640
Const YRES=480

bglCreateContext(XRES,YRES,32,0,BGL_BACKBUFFER|BGL_DEPTHBUFFER|BGL_FULLSCREEN)

'
' setup OpenGL for 2D Drawing
'
glMatrixMode 	(GL_PROJECTION)
glLoadIdentity	()
gluOrtho2D	(0, XRES, YRES, 0)
glMatrixMode 	(GL_MODELVIEW)
glLoadIdentity	()
glDisable 	(GL_DEPTH_TEST)	'you may want to disable depth testing so 
							'you can define the render order exactly
'
'Image Properties
'
Global Locked:TPixmap

Global Image=LoadImage("../media/Image.Bmp",DynamicImage)

Global IW=ImageWidth(Image)
Global IH=ImageHeight(Image)

Global ImageData#[IW,IH,4]

create2DImage()

'
' the main loop
'
While Not KeyHit(KEY_ESCAPE)
	
	Draw2D()

	bglSwapBuffers
	
Wend



Function Draw2D()

glBegin (GL_Points)
	
	For Local y= 0 To IH-1
		For Local x=0 To IW-1
			
			glcolor3f( ImageData[x,y,1] , ImageData[x,y,2], ImageData[x,y,3] )		
			glVertex2f (x, y )					
		
		Next
	Next
		
glEnd()

End Function



Function Create2DImage()

Locked=LockImage(Image)

For Local y=0 To IH-1
	For Local x=0 To IW-1
		
		Local RGB=ReadPixel(Locked,x,y)
		
		'
		' convert to 0-255 colours
		'
		Local Red=(RGB Shr 16) & 255
		Local Grn=(RGB Shr  8) & 255
		Local Blu=(RGB Shr  0) & 255
		
		'
		' convert to OpenGL values
		'		
		Local Red2#= 1.0 / (255.0 * Red) 
		Local Grn2#= 1.0 / (255.0 * Grn)
		Local Blu2#= 1.0 / (255.0 * Blu)
		
		'
		' store the results.
		'
		ImageData[x,y,1]=Red2
		ImageData[x,y,2]=Grn2
		ImageData[x,y,3]=Blu2

	Next
Next

UnlockImage (Image)

End Function


And as you'll see with using your own images with the example, that the colours are still a tad wrong.

Big Thanks,
THUMBZ

I couldn't get this code to work!!

gluOrtho2D(left,right,bottom,top) -<you set it up as left,right,top,bottom !!
should be gluOrtho(0,xres,0,yres)

then I get a blank screen. Doesn't seem to be reading the image I have here.[EDIT] image I used was too big.

Ok I got it working. I assume you have it working but this colors are wrong, so you need to do this:

Local Red2#= 1.0 - 1.0 / (255.0 * Red)
Local Grn2#= 1.0 - 1.0 / (255.0 * Grn)
Local Blu2#= 1.0 - 1.0 / (255.0 * Blu)

Thanks Col.

I've Just tried it out and the colours are still off.
I wonder if it's do to with the Red, Grn and Blu before converting to OpenGL Colours?

Local Red2#= (1.0 / 255.0) * Red
Local Grn2#= (1.0 / 255.0) * Grn
Local Blu2#= (1.0 / 255.0) * Blu
e.g....
Local Red2#= (1.0 / 255.0) * (Red/2)
Local Grn2#= (1.0 / 255.0) * (Grn/2)
Local Blu2#= (1.0 / 255.0) * (Blu/2)
is half colour
P.S the way to think about it is...
255 = 1.0
1 = 1.0/255
RED = (1.0/255)*RED

doh. Of course.

That was what I meant ;) ...........hhmmmm

Greatest!

Thanks for your help.
And I'll post back in a little while, if I cant get the next step in Blurring the image working.

Here's an attempted fader, as you'll witness the colours dont really fade very well.

And I've not had much luck with doing a blurring effect based on this approach. Any ideas?
'
' OPENGL 2D Drawing Test Example
'

Const XRES=640
Const YRES=480

bglCreateContext(XRES,YRES,32,0,BGL_BACKBUFFER|BGL_DEPTHBUFFER|BGL_FULLSCREEN)

'
' setup OpenGL for 2D Drawing
'
glMatrixMode 	(GL_PROJECTION)
glLoadIdentity	()
gluOrtho2D	(0, XRES, YRES, 0)

glClearColor	(0.0, 0.0, 0.0, 0.0)

glMatrixMode 	(GL_MODELVIEW)
glLoadIdentity	()
glDisable 	(GL_DEPTH_TEST)	 


							
'
'Image Properties
'
Global Locked:TPixmap

Global Image	=LoadImage("../media/imagery.png", DynamicImage )

Global IW		=ImageWidth ( Image )
Global IH		=ImageHeight( Image )

Global ImageData#	[ IW,IH,4]

Global RedData#	[ IW, IH ]
Global GrnData#	[ IW, IH ]
Global BluData#	[ IW, IH ]

create2DImage()


'
' Clear the images.
'
Image	=Null
Locked	=Null


'
' the main loop
'
While Not KeyHit(KEY_ESCAPE)
	
	Draw2D()
	UpdateColours()
	bglSwapBuffers
	FlushMem	
Wend



Function Draw2D()

'
' Start point drawing.
'
glBegin (GL_Points)
	
	For Local y= 0 To IH-1
		For Local x=0 To IW-1
			
			glcolor3f	( RedData[x,y] , GrnData[x,y], BluData[x,y] )		
			glVertex2f( x, y )					
		
		Next
	Next
		
glEnd()


End Function


'
' Read in image and store pixel colourings.
'
Function Create2DImage()

Locked=LockImage(Image)

For Local y=0 To IH-1
	For Local x=0 To IW-1
		
		Local RGB=ReadPixel(Locked,x,y)
		
		'
		' convert to 0-255 colours
		'
		Local Red=(RGB Shr 16) & 255
		Local Grn=(RGB Shr  8) & 255
		Local Blu=(RGB Shr  0) & 255
		
		'
		' convert to OpenGL values
		'		
		Local Red2#= (1.0 / 255.0) * Red
		Local Grn2#= (1.0 / 255.0) * Grn
		Local Blu2#= (1.0 / 255.0) * Blu 

		'
		' store the results.
		'
		ImageData[x,y,1]=Red2
		ImageData[x,y,2]=Grn2
		ImageData[x,y,3]=Blu2
		
		RedData[x,y]=Red2
		GrnData[x,y]=Grn2
		BluData[x,y]=Blu2
		
	Next
Next

UnlockImage (Image)
End Function


'
' Perform colour fade.
'
Function UpdateColours()

For y=0 To IH-1
	For x=0 To IW-1
	
	'
	' Decrease the R/G/B Values.
	'
	RedData[x,y]=RedData[x,y]-.01
	GrnData[x,y]=GrnData[x,y]-.01
	BluData[x,y]=BluData[x,y]-.01	
	
	'
	' If Lower then 0.0 then reset the to starting value.
	'
	If RedData[x,y]<0.0 Then RedData[x,y]=ImageData[x,y,1] 
	If GrnData[x,y]<0.0 Then GrnData[x,y]=ImageData[x,y,2] 
	If BluData[x,y]<0.0 Then BluData[x,y]=ImageData[x,y,3] 
	
	Next
Next	
		
End Function


Humble Thankyous,
THUMBZ

Here's an attempted fader, as you'll witness the colours dont really fade very well.


I put some fader routines in the Code Archives the other day.

Are they OpenGL ones?
Will take another look.

I've done a normal MAX2D starfield, and an OpenGL one. And I'm highly surprised by the difference in Frame Rate.

OPEN GL METHOD: 482 FPS
'
' OPENGL 2D Drawing Test Example
'

Const XRES=640
Const YRES=480
Const RRES= 32

bglCreateContext(XRES,YRES,RRES,0,BGL_BACKBUFFER |BGL_DEPTHBUFFER |BGL_FULLSCREEN )
bglSetMouseVisible False

'
' setup OpenGL for 2D Drawing
'
InitOpenGL()

'
' Data Setup 
'
Const PixelAmount=8000

Global MapDataX#[ PixelAmount ]
Global MapDataY#[ PixelAmount ]

Global RedData#	[ PixelAmount ]
Global GrnData#	[ PixelAmount ]
Global BluData#	[ PixelAmount ]
Global AlpData# [ PixelAmount ]

Global XSpeed#	[ PixelAmount ]

Global PosX,PosY

Create2DImage()


' 
' Frames Per Second
'
Global FPS_Count		= 0
Global FPS_Timer
Global FrameCounter
Global FrameRate		= 0


'
' the main loop
'
While Not KeyHit(KEY_ESCAPE)
	
	Draw2D			()
	Update2D		()
	
	OpenGLPrintText	()
	
	bglSwapBuffers	()
	FlushMem		()	
	FPS				()
Wend

EndGraphics




'
' setup OpenGL for 2D Drawing
'
Function InitOpenGL()

glMatrixMode 	(GL_PROJECTION)
glLoadIdentity	()
gluOrtho2D		(0, XRES, YRES, 0)

glClearColor	(0.0, 0.0, 0.0, 0.0)

glMatrixMode 	(GL_MODELVIEW)
glLoadIdentity	()
glDisable 		(GL_DEPTH_TEST)	 

glBlendFunc		(GL_SRC_ALPHA,GL_ONE)
glEnable		(GL_BLEND)	

End Function	



Function Draw2D()

'
' Start point drawing.
'
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

glBegin (GL_Points)
	
	For Local a= 0 To PixelAmount-1
		
		glcolor4f ( RedData[a] , GrnData[a], BluData[a] ,AlpData[a] )		
		
		glVertex2f( MapDataX[a],MapDataY[a] )					
	
	Next
	
		
glEnd()


End Function


'
' Read in image and store pixel colourings.
'
Function Create2DImage()

For Local a=0 To PixelAmount-1
	
	PosX			=Rand( XRES )
	PosY			=Rand( YRES )
	
	MapDataX[ a ]	=PosX
	MapDataY[ a ]	=PosY		
	
	AlpData [ a ] 	=Rnd( 1 )
	RedData	[ a ]	=Rnd( 1 )
	GrnData	[ a ]	=Rnd( 1 )
	BluData	[ a ]	=Rnd( 1 )
	
	XSpeed	[ a ]	=Rnd( 3 )
	
Next

End Function



Function Update2D()

For Local a=0 To PixelAmount-1
	
	MapDataX[ a ]=MapDataX[ a ]+XSpeed[ a ]
	
	If  MapDataX[ a ]>XRES Then 

		PosY			=Rand( YRES )
	
		MapDataX[ a ]	=-1
		MapDataY[ a ]	=PosY
	
		AlpData [ a ] 	=Rnd( 1 )
		RedData	[ a ]	=Rnd( 1 )
		GrnData	[ a ]	=Rnd( 1 )
		BluData	[ a ]	=Rnd( 1 )
	
		XSpeed	[ a ]	=Rnd( 3 )
	
	End If


Next


End Function



Function OpenGLPrintText()
	
	glColor3f	(1.0,1.0,1.0)
	
	bglDrawText	("FPS : "+FPS_Count,0,0)
	
End Function



Function FPS()

FrameCounter = FrameCounter + 1

If FPS_Timer+1000 <= MilliSecs() Then
	FPS_Count		= FrameCounter
	FPS_Timer		= MilliSecs()
	FrameCounter	= 0
End If
	
If FPS_Count<=1 Then
	Return FrameRate
Else	
	Return FPS_Count
End If

End Function


BMAX 2D METHOD: 60 FPS
'2D Comparison

Const XRES=640
Const YRES=480
Const RRES= 32

Graphics XRES,YRES,RRES
HideMouse

'
' Data Setup 
'
Const PixelAmount=8000

Global MapDataX#[ PixelAmount ]
Global MapDataY#[ PixelAmount ]

Global RedData	[ PixelAmount ]
Global GrnData	[ PixelAmount ]
Global BluData	[ PixelAmount ]
Global AlpData# [ PixelAmount ]

Global XSpeed#	[ PixelAmount ]

Create2D()

Global PosX,PosY

' 
' Frames Per Second
'
Global FPS_Count		= 0
Global FPS_Timer
Global FrameCounter
Global FrameRate		= 0




'
' the main loop.
'
While Not KeyHit(KEY_ESCAPE)
Cls

	Draw2D		()
	Update2D	()

	PrintText	()
	FlushMem	()
	FPS()
Flip
Wend


'
' Read in image and store pixel colourings.
'
Function Create2D()

For Local a=0 To PixelAmount-1
	
	PosX			=Rand( XRES )
	PosY			=Rand( YRES )
	
	MapDataX[ a ]	=PosX
	MapDataY[ a ]	=PosY		
	
	AlpData [ a ] 	=Rnd( 1 )
	RedData	[ a ]	=Rand( 255 )
	GrnData	[ a ]	=Rand( 255 )
	BluData	[ a ]	=Rand( 255 )
	
	XSpeed	[ a ]	=Rnd( 3 )
	
Next

End Function


Function Draw2D()

For Local a=0 To PixelAmount-1
	
	SetBlend ALPHABLEND
	
	SetColor RedData[a],GrnData[a],BluData[a]
	SetAlpha AlpData[a]
	
	Plot MapDataX[a],MapDataY[a]

Next


End Function



Function Update2D()

For Local a=0 To PixelAmount-1
	
	MapDataX[ a ]=MapDataX[ a ]+XSpeed[ a ]
	
	If  MapDataX[ a ]>XRES Then 

		PosY			=Rand( YRES )
	
		MapDataX[ a ]	=-1
		MapDataY[ a ]	=PosY
	
		AlpData [ a ] 	=Rnd( 1 )
		RedData	[ a ]	=Rand( 255 )
		GrnData	[ a ]	=Rand( 255 )
		BluData	[ a ]	=Rand( 255 )
	
		XSpeed	[ a ]	=Rnd( 3 )
	
	End If


Next


End Function



Function PrintText()
	
	SetBlend SOLIDBLEND
	SetColor 255,255,255
		
	DrawText ("FPS : "+FPS_Count,0,0)
	
End Function



Function FPS()

FrameCounter = FrameCounter + 1

If FPS_Timer+1000 <= MilliSecs() Then
	FPS_Count		= FrameCounter
	FPS_Timer		= MilliSecs()
	FrameCounter	= 0
End If
	
If FPS_Count<=1 Then
	Return FrameRate
Else	
	Return FPS_Count
End If

End Function


I would really love some help in making the OpenGL method make the starfield blur. Many thanks in that department.

Edit: I think I may need to alter the way it stores the x and y positions and colours. Let me know, it a blur is doable, or how'd you'd go about it. Im having great fun with GL.

Thanks,
THUMBZ

I'm not surprised, Flip command use a delay. ;)

Im running into allsorts of problems, most especially understanding OpenGL and BMAX. So with one last and final attempt, I came up with this which is pathetic really. I need lots of help, as BMAX is alot lot different then previous versions. Documention and stuff is pretty lapse at the momemt.

If any of these trials and tribulations of mine are of any use to somebody, then the experimenting was worth it.

'
' OPENGL 2D Drawing Test Example
'

Const XRES=640
Const YRES=480
Const RRES= 32

bglCreateContext(XRES,YRES,RRES,0,BGL_BACKBUFFER |BGL_DEPTHBUFFER |BGL_FULLSCREEN )
bglSetMouseVisible False

InitOpenGL()


Const TotalAmount=1000

Global PixelsX#[TotalAmount]
Global PixelsY#[TotalAmount]

Global RedData#[XRES,YRES]
Global GrnData#[XRES,YRES]
Global BluData#[XRES,YRES]
Global AlpData#[XRES,YRES]

Populate()


' 
' Frames Per Second
'
Global FPS_Count		= 0
Global FPS_Timer
Global FrameCounter
Global FrameRate		= 0


'
' The main loop.
'
While Not KeyHit(KEY_ESCAPE)
	
	Draw2D			()
	Update2D		()
	OpenGLPrintText	()
	bglSwapBuffers	()
	FPS()
Wend





'
' setup OpenGL for 2D Drawing
'
Function InitOpenGL()

glMatrixMode 	(GL_PROJECTION)
glLoadIdentity	()
gluOrtho2D		(0, XRES, YRES, 0)

glClearColor	(0.0, 0.0, 0.0, 0.0)

glMatrixMode 	(GL_MODELVIEW)
glLoadIdentity	()
glDisable 		(GL_DEPTH_TEST)	 

glBlendFunc		(GL_SRC_ALPHA,GL_ONE)
glEnable		(GL_BLEND)	

End Function



Function Draw2D()

'
' Start point drawing.
'
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

glBegin (GL_Points)
	
	For Local a=0 To TotalAmount-1
			
		PosX#=PixelsX[a]
		PosY#=PixelsY[a]
		
		glcolor4f ( RedData[PosX,PosY] , GrnData[PosX,PosY], BluData[PosX,PosY] ,AlpData[PosX,PosY] )		
			
		glVertex2f( PixelsX[a],PixelsY[a] )					
		
	Next
		
glEnd()


End Function



Function Populate()

For Local a=0 To TotalAmount-1

	Local PosX=Rand(XRES)
	Local PosY=Rand(YRES)
	
	PixelsX[a]=PosX
	PixelsY[a]=PosY
	
	RedData[PosX,PosY]=rnd(1)
	GrnData[PosX,PosY]=rnd(1)
	BluData[PosX,PosY]=rnd(1)
	AlpData[PosX,PosY]=1

Next

End Function


Function Update2D()

For y=1 To YRES-1
	For x=1 To XRES-1
		
		Local RED#=(( RedData[x,y] + RedData[x - 1,y] + RedData[x + 1,y] + RedData[x,y + 1] ) / 2 )
		Local GRN#=(( GrnData[x,y] + GrnData[x - 1,y] + GrnData[x + 1,y] + GrnData[x,y + 1] ) / 2 )
		Local BLU#=(( BluData[x,y] + BluData[x - 1,y] + BluData[x + 1,y] + BluData[x,y + 1] ) / 2 )

		RedData[x,y]=Red
		GrnData[x,y]=Grn
		BluData[x,y]=Blu
	Next
Next

For Local a=0 To TotalAmount-1
	
	PixelsX[a]=PixelsX[a]+.1	
	
	If PixelsX[a]>XRES Then 
		
		PixelsX[a]=0
		
		PosY=Rand(YRES)
		
		PixelsY[a]=PosY
		
		RedData[0,PosY]=rnd(1)
	
	End If
	
Next


End Function



Function OpenGLPrintText()
	
	glColor3f	(1.0,1.0,1.0)
	
	bglDrawText	("FPS : "+FPS_Count,0,0)
	
End Function



Function FPS()

FrameCounter = FrameCounter + 1

If FPS_Timer+1000 <= MilliSecs() Then
	FPS_Count		= FrameCounter
	FPS_Timer		= MilliSecs()
	FrameCounter	= 0
End If
	
If FPS_Count<=1 Then
	Return FrameRate
Else	
	Return FPS_Count
End If

End Function


Just like to say a big thankyou to everyone who've helped me with my dabbling into BMAX and OpenGL.

Thanks Heaps,
THUMBZ

What should that code do?
It crashes on my old FX5200
BMAX 2D METHOD: 60 FPS works at 61 FPS;-)

Cool, some useful info to be had there. So, thanks.

Oh so very new to the BlitzMax scene, and though there is much to like, I confess I miss the lockedbuffer-writepixelfast performance of BlitzPlus, which although not uber-fast itself, was plenty fast enough to do lots of really cool particle stuff, whilst retaining respectable system requirements. Doing tests using pixmaps, which seem to be the fastest way of producing similar functionality yielded results that were generally quite a bit quicker than both (B+) Plot and Writepixel, but still (understandably) blown away by the lockedbuffer performance.

Now, after some perusal of this thread (and the contents of the bmax modules), I have a couple of functions for performing pixel writing operations that seem on the whole to run only 5-10% slower than a locked writepixelfast, with the added bonus of having alpha. Particle extravagansa, here I come!

Of course, this is only OpenGL. DirectX seems to be a lot more convoluted, and I haven't been able to create equivalent functionality in the DX environment yet.

wow.. this thread was over 7 months old.. :p

Useful threads don't go off with age. :P

I have been in possession of BMax for roughly 72 hours. I have much ground to cover. Admittedly, I was hoping a search would return more recent threads. Surely I can't be the only person hoping to do lots of 2D pixel particle effects?

Plotting your own particles (vertexes) with glVertex is going to be a lot faster than using Plot because you remove the overhead.

With regards to the grayscale thing, a simple way to do it is to convert the image to a one-channel texture, like Red only, where Red=Red+Green+Blue /3

Upload the one-channel texture to the gfx card as a GL_ALPHA texture. Then draw it, using a blend mode, which takes the alpha channel of the source data and expands it into each color component - ie if alpha is 200, then RG and B all become 200. That turns it into a grayscale representation. Probably faster overall than doing the whole conversion in main memory.

Yes indeed, thus far, glvertex is doing a splendid job, and in general, it seems to be running as quickly as writepixelfast did, even with a color and alpha function. Very useful. Can't be bothered trying to get d3d to do the same anymore, ridiculous cruddy API. I've decided to stick with OpenGL, it's proven far more cooperative, plus that makes everything ready to cross the great platform divide.