letters appear as squares

BlitzMax Forums/BlitzMax Programming/letters appear as squares

Najdorf(Posted 2007) [#1]
Some people trying my game say that everything ( letters and images) appear as squares. This seems to be mostly on Vista machines

I'm using the Max2D module (with opengl, not directX), does anybody know what's the problem? Should I switch to directx?


tonyg(Posted 2007) [#2]
I would guess it is a driver issue so switching to DX is a good idea or let the user decide.


Grey Alien(Posted 2007) [#3]
I would always default to DirectX and only allow OpenGL if the user chooses it.


Tricky(Posted 2007) [#4]
I noticed this happens especially when you use Pixmaps in stead of images. And strangly only in graphics mode. The Pixmaps used in MaxGUI handled themselves fine to me (except those which were in a Canvas).


xlsior(Posted 2007) [#5]
It could be that there isn't enough graphics memory available on the video card... Any idea how much they have?


marksibly(Posted 2007) [#6]
I suspect it's a GL-driver-on-Vista issue - try DirectX, or see if one of the people experiencing the problem can update their video drivers.


slenkar(Posted 2008) [#7]
I get this too on windowsXP
with an intel integrated graphics card


slenkar(Posted 2008) [#8]
dbl post


Dreamora(Posted 2008) [#9]
update the driver or forget OpenGL.
The GMA 900 for example falls back into Microsoft OpenGL 1.1 emulation mode ... this is less than Max2D needs (OGL 1.2)


slenkar(Posted 2008) [#10]
ive played lots of commercial games which use opengl without any problems,
the drivers are updated


tonyg(Posted 2008) [#11]
What is the simplest example which shows the problem? How many graphics are involved? What happens with DX? What happens if you use smaller graphics or less of them? What is the machine specs?What level of Bmax are you using? What OGL driver levels?


slenkar(Posted 2008) [#12]
I did some investigation and its because I was setting the blend mode to alpha blend.
dont know why it behaves differently from GL to D3d


GfK(Posted 2008) [#13]
Just got a laptop with Intel GMA965 graphics and Vista on it - OpenGL in Blitzmax simply doesn't work (white squares for everything), whereas all the other GL stuff I tried, does.

There has to be a way to fix this?

PS. My drivers are bang up-to-date - got them from the Intel website and they were only released 9 days ago, so they're about as new as you can get.


tonyg(Posted 2008) [#14]
What about pixmaps?


GfK(Posted 2008) [#15]
Three screenshots taken on a Mobile Intel GMA X3100. I was planning just to tell you the results, but how the hell do you describe this?:


DrawPixmap works if I use JPG format, but I need PNGs with alpha, and DrawPixmap is phenomenally slow. DrawImage with a JPG is solid white, as above.


marksibly(Posted 2008) [#16]
Can someone post a code sample?


GfK(Posted 2008) [#17]
Here's more or less what I used to get the results above (flare1.png is a 24-bit PNG with alpha channel):
SetGraphicsDriver GLMax2DDriver()

Graphics 800,600

Global img:timage = LoadImage("flare1.png")
Global px:TPixmap = LockImage(img)

While Not KeyDown(KEY_ESCAPE)
	Cls
	DrawImage img,200,300
	DrawPixmap px,400,300
	Flip
Wend



marksibly(Posted 2008) [#18]
Can you please post a link to flare1.png or email it to me.


GfK(Posted 2008) [#19]
Check your e-mail (the one in your profile).

Didn't want to post it here cos its an asset from my current game.


marksibly(Posted 2008) [#20]
Hi,

I don't get your 'whiterect' effect with the GL driver, so I assume this is a driver thing.

Use 'SetBlend ALPHABLEND' to perform proper alpha blending instead of the default MASKBLEND-ing. Adding this to your example works for me.

DrawPixmap does not perform blending at all - it effectively works in SOLIDBLEND mode.


GfK(Posted 2008) [#21]
Mark - sorry, should have said. I tried all the blendmodes before and I get the same results as above, whatever I do.

What hardware are you testing on?


marksibly(Posted 2008) [#22]

What hardware are you testing on?


Windows XP + GeForce8800.

What does this do?

Strict

GLGraphics 640,480

glEnable GL_TEXTURE_2D
glBindTexture GL_TEXTURE_2D,1

glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR
glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR

Local pixmap:TPixmap=LoadPixmap( "flare1.png" )
glTexImage2D GL_TEXTURE_2D,0,GL_RGBA8,pixmap.width,pixmap.height,0,GL_RGBA,GL_UNSIGNED_BYTE,pixmap.pixels

glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA

While Not KeyHit( KEY_ESCAPE )

	glClear GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT
	
	glBegin GL_QUADS
	glTexCoord2f 0,0
	glVertex2f -1,-1
	glTexCoord2f 1,0
	glVertex2f 1,-1
	glTexCoord2f 1,1
	glVertex2f 1,1
	glTexCoord2f 0,1
	glVertex2f -1,1
	glEnd
	
	Flip
	
Wend



GfK(Posted 2008) [#23]
I get the flare image, stretched out across the full window. Is that right?

(That GL stuff frightens me).

BTW: I'm testing on a Compaq Presario C757, Pentium Dual Core 1.46GHz, Intel GMA X3100 graphics, 2GB RAM, Vista Home Premium.

From what I've read, the shared graphics memory on these things is allocated as needed up to something like 384MB. I'm not sure if this is anything to do with textures not appearing in Blitzmax under GLMax2DDriver. Probably worth mentioning anyway.


marksibly(Posted 2008) [#24]
How about this:


Strict

GLGraphics 640,480

Local pixmap:TPixmap=LoadPixmap( "flare1.png" ),flags=MASKEDIMAGE | FILTEREDIMAGE

Local tex=CreateTex( pixmap.width,pixmap.height,flags )

glEnable GL_TEXTURE_2D
glBindTexture GL_TEXTURE_2D,tex

UploadTex pixmap,flags

glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA

While Not KeyHit( KEY_ESCAPE )

	glClear GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT
	
	glBegin GL_QUADS
	glTexCoord2f 0,0
	glVertex2f -1,-1
	glTexCoord2f 1,0
	glVertex2f 1,-1
	glTexCoord2f 1,1
	glVertex2f 1,1
	glTexCoord2f 0,1
	glVertex2f -1,1
	glEnd
	
	Flip
	
Wend

End

Function CreateTex( width,height,flags )

	Local name
	glGenTextures 1,Varptr name

	glBindTexture GL_TEXTURE_2D,name
	'set texture parameters

	glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE
	glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE
	
	If flags & FILTEREDIMAGE
		glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR
		If flags & MIPMAPPEDIMAGE
			glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR
		Else
			glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR
		EndIf
	Else
		glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST
		If flags & MIPMAPPEDIMAGE
			glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST
		Else
			glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST
		EndIf
	EndIf

	Local mip_level

	Repeat
		glTexImage2D GL_TEXTURE_2D,mip_level,GL_RGBA8,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,Null
		If Not (flags & MIPMAPPEDIMAGE) Exit
		If width=1 And height=1 Exit
		If width>1 width:/2
		If height>1 height:/2
		mip_level:+1
	Forever
	Return name
End Function

Function UploadTex( pixmap:TPixmap,flags )
	Local mip_level
	Repeat
		glPixelStorei GL_UNPACK_ROW_LENGTH,pixmap.pitch/BytesPerPixel[pixmap.format]
		glTexSubImage2D GL_TEXTURE_2D,mip_level,0,0,pixmap.width,pixmap.height,GL_RGBA,GL_UNSIGNED_BYTE,pixmap.pixels
		If Not (flags & MIPMAPPEDIMAGE) Exit
		If pixmap.width>1 And pixmap.height>1
			pixmap=ResizePixmap( pixmap,pixmap.width/2,pixmap.height/2 )
		Else If pixmap.width>1
			pixmap=ResizePixmap( pixmap,pixmap.width/2,pixmap.height )
		Else If pixmap.height>1
			pixmap=ResizePixmap( pixmap,pixmap.width,pixmap.height/2 )
		Else
			Exit
		EndIf
		mip_level:+1
	Forever
	glPixelStorei GL_UNPACK_ROW_LENGTH,0
End Function



GfK(Posted 2008) [#25]
Same as your first bit of code. Flare texture, stretched across the whole window.


marksibly(Posted 2008) [#26]
One more:


Strict

GLGraphics 640,480

Local pixmap:TPixmap=LoadPixmap( "flare1.png" ),flags=MASKEDIMAGE | FILTEREDIMAGE

GLGraphicsDriver().SwapSharedContext
Local tex=CreateTex( pixmap.width,pixmap.height,flags )
UploadTex pixmap,flags
GLGraphicsDriver().SwapSharedContext

glEnable GL_TEXTURE_2D
glBindTexture GL_TEXTURE_2D,tex

glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA

While Not KeyHit( KEY_ESCAPE )

	glClear GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT
	
	glBegin GL_QUADS
	glTexCoord2f 0,0
	glVertex2f -1,-1
	glTexCoord2f 1,0
	glVertex2f 1,-1
	glTexCoord2f 1,1
	glVertex2f 1,1
	glTexCoord2f 0,1
	glVertex2f -1,1
	glEnd
	
	Flip
	
Wend

End

Function CreateTex( width,height,flags )

	Local name
	glGenTextures 1,Varptr name

	glBindTexture GL_TEXTURE_2D,name
	'set texture parameters

	glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE
	glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE
	
	If flags & FILTEREDIMAGE
		glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR
		If flags & MIPMAPPEDIMAGE
			glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR
		Else
			glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR
		EndIf
	Else
		glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST
		If flags & MIPMAPPEDIMAGE
			glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST
		Else
			glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST
		EndIf
	EndIf

	Local mip_level

	Repeat
		glTexImage2D GL_TEXTURE_2D,mip_level,GL_RGBA8,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,Null
		If Not (flags & MIPMAPPEDIMAGE) Exit
		If width=1 And height=1 Exit
		If width>1 width:/2
		If height>1 height:/2
		mip_level:+1
	Forever
	Return name
End Function

Function UploadTex( pixmap:TPixmap,flags )
	Local mip_level
	Repeat
		glPixelStorei GL_UNPACK_ROW_LENGTH,pixmap.pitch/BytesPerPixel[pixmap.format]
		glTexSubImage2D GL_TEXTURE_2D,mip_level,0,0,pixmap.width,pixmap.height,GL_RGBA,GL_UNSIGNED_BYTE,pixmap.pixels
		If Not (flags & MIPMAPPEDIMAGE) Exit
		If pixmap.width>1 And pixmap.height>1
			pixmap=ResizePixmap( pixmap,pixmap.width/2,pixmap.height/2 )
		Else If pixmap.width>1
			pixmap=ResizePixmap( pixmap,pixmap.width/2,pixmap.height )
		Else If pixmap.height>1
			pixmap=ResizePixmap( pixmap,pixmap.width,pixmap.height/2 )
		Else
			Exit
		EndIf
		mip_level:+1
	Forever
	glPixelStorei GL_UNPACK_ROW_LENGTH,0
End Function


(Make sure to test on GMA!)


GfK(Posted 2008) [#27]
That last one results in a white screen.


marksibly(Posted 2008) [#28]
Aha!

GMA doesn't like shared GL contexts...


GfK(Posted 2008) [#29]
I have no idea what that means! :D

Can you mend it?


Dreamora(Posted 2008) [#30]
don't know how large the texture is but tested both of the codes with a 32x32 png image on XP with 8800GTS 640MB (169.28 drivers, most current from eVGA and newer than the WHQL certified on nvidia.com) and they both stretch the image over the whole screen.


marksibly(Posted 2008) [#31]

Can you mend it?


Maybe.

Any particular reason you're not using DX driver?


GfK(Posted 2008) [#32]
I am, mainly. But a lot of people prefer to use OpenGL so I'd like to at least give them the option.

There's a hell of a lot of these Intel GMA things about nowadays. It'd be great if it could be made to work.


GfK(Posted 2008) [#33]
Any news on this being fixed yet? Its really annoying that I can't run any BlitzMax stuff that uses GL!


SLotman(Posted 2008) [#34]
Yeah, I'm waiting this to be fixed too... it's what been putting me off to purchase blitzmax and eventually using it on my next game =(


Qube(Posted 2008) [#35]

Any particular reason you're not using DX driver?



Personally I find the GL driver quite a bit faster than the DX version, so a fix with others incompatibilities would be very welcome indeed :)


klepto2(Posted 2008) [#36]
This can't be fixed that easy, its a gfx driver (hardware)) problem, not a problem with max2d. On Windows dx is the most comaptible one. Even if opengl maybe faster on your machine it doesn't mean it will be on others. thats the reason why we add dx support to minib3d extended.


GfK(Posted 2008) [#37]
Its absolutely a problem with Max2D. Everything else I've ever tried that uses GL works without problems.

It needs to be fixed, otherwise BRL might as well terminate GL support in Blitzmax if it can't be relied upon to work correctly under Windows.


Dreamora(Posted 2008) [#38]
what is your hardware?
If you say intel, then it is a driver issue.
If you say ATI: get current drivers. 8.1 is known to solve a fair load of OpenGL bugs.

And OGL is faster on any DX9 level hardware actually mainly because DX7 drivers never got really 3D optimized, while OpenGL ones did.


SLotman(Posted 2008) [#39]
The main reason to stick with OGL is portability.

Even if you can specify the use of DX on Windows, If I need to write some custom function to do something not implemented that I need - I wouldnt want to have to write that twice to work both on OpenGL *and* Direct-X.

If I wanted some 2D DX7 code, I still have my own 2D engine I did when DX7 was out (which didnt use any 3D at all and could run even on a Trident 1mb card hehehe), even made some games out of it (Revenge of the TimeLord and Frosted if anyone here ever saw them)

My point is, the best feature of BMax is portability and the "write once, compile everywhere" idea. And if it's having trouble with Intel's GMA chipset (which is now everywhere on laptops), it is a big problem in my book.

Have anyone tested to see if this also happens on Linux machines with those GMAs? This would clarify if it's a drivers problem or an incompatibility with the way BlitzMax handles OGL stuff.


GfK(Posted 2008) [#40]
If you say intel, then it is a driver issue.
Argh! ITS NOT A DRIVER ISSUE! Stop telling me its a driver problem when I know 100% it isn't! Everything else for GL works perfectly. Blitzmax GL stuff does not work. It is not the drivers! OK?! :/

If you bothered to actually read threads instead of just bombarding the forums with a hundred replies a day and an opinion on everything, you'd already know its Intel GMA hardware (actually you would have known that when you pointlessly 'tested' an Intel GMA problem on Nvidia hardware last week in this very thread).

This would clarify if it's a drivers problem or an incompatibility with the way BlitzMax handles OGL stuff.
This is what Mark said it is, above (shared GL contexts). Can it be fixed? Mark says "maybe".


marksibly(Posted 2008) [#41]

Argh! ITS NOT A DRIVER ISSUE! Stop telling me its a driver problem when I know 100% it isn't!


Our experiments above suggest that Intel's implementation of shared GL contexts is either borked or, at the least, flaky. The same shared context code works fine on a bunch of other OS/card combos.

Not all GL apps use shared contexts (esp. games) so not all apps suffer from problems like this - which of course doesn't mean there isn't a problem.

I have some ideas for hacks/fixes which I'll try out soon, but in the meantime I'm locking this as it's getting shouty.