text() not working right on some machines?
Blitz3D Forums/Blitz3D Programming/text() not working right on some machines?
| ||
Hi there. I'm creating gauges for a driving sim and the numbers on the speedometer aren't showing up on one computer, but work fine on another. Other draw commands work fine on the texture; just the text isn't showing up. I've extracted the error, so to speak, to the code below. See toward the end for comments showing the command that works and the command that doesn't. When you run it you will see a red box with text in the middle; that one should work fine. There will also be a blue and black box in the lower left. The text in that box is the problem (the white circle should work fine). I'm curious if it's just some weirdness with my ex-wife's computer or if others have the same problem. And, of course, what the cause is. Thanks in advance! Graphics3D 1024,768,32,2 Global Camera Global thing setup() Const GameUPS=60 ; Updates per second Local Period=1000/GameUPS Local FrameTime=MilliSecs()-Period Local Tween#, Ticks,i,Remaining,StartTime,Elapsed While Not KeyHit(1) StartTime = MilliSecs() Repeat Elapsed=MilliSecs()-FrameTime Until Elapsed Ticks=Elapsed / Period Tween=Float(Elapsed Mod Period)/Float(Period) For i=1 To Ticks FrameTime=FrameTime+Period If i=Ticks Then CaptureWorld End If UpdateWorld Next RenderWorld Tween Remaining = Period - (MilliSecs() - StartTime) If Remaining > 1 Then Delay (Remaining-1) ; Free some CPU time End If Flip Wend End Function setup() Camera=CreateCamera() PositionEntity(Camera,0,0,-3) createGauges() End Function Function createGauges() ;Speedometer ;Create the big red square thing=CreateSprite() Local tex=CreateTexture(256,256) SetBuffer(TextureBuffer(tex)) Color(255,0,0) Rect(0,0,256,256,1) Color(255,255,255) Text(128,128,"10 20 30 40 50 60",1,1) EntityTexture(thing,tex) ;Now create the speedometer in the lower left Local speedGaugeBG,txt Local txtSize=256 speedGaugeBG=CreateSprite() ;ScaleSprite(speedGaugeBG,.5,.5) ;EntityOrder(speedGaugeBG,-10) txt=CreateTexture(txtSize,txtSize,6) SetBuffer(TextureBuffer(txt)) Color(0,0,255) Rect(0,0,txtSize,txtSize) Color(0,0,0) Oval(1,1,txtSize-2,txtSize-2) Color(255,255,255) Oval(100,100,10,10,1); <------- This line works everywhere Text (10,10,"The text works!") ; <------- This line works on some machines, not others EntityTexture(speedGaugeBG,txt) ;Create the grey plane to view against plane=CreatePlane() MoveEntity(plane,0,-10,0) ;Position it EntityParent(speedGaugeBG,Camera) PositionEntity(speedGaugeBG,-1,-1.3,2.3) RotateEntity(speedGaugeBG,0,0,0) SetBuffer(BackBuffer()) End Function |
| ||
The text that is missing is being allocated to the red square. It's 0,0 is the top left of the red square. EDIT: Or maybe not. Last edited 2010 |
| ||
Seems to be due to the texture buffer. |
| ||
It's down to individual GFX cards/drivers. 2D is very poorly supported, these days. Works on some, not on others. |
| ||
You'll have to reuse 'SetBuffer(TextureBuffer(tex))' prior to showing the missing text. EDIT: Ah, but that puts it back inside the red square. Last edited 2010 |
| ||
You guys are awesome for responding so quick! Puki: You would have to use txt not tex ; that's why it showed up in the red square. I tried it with txt and it did not fix the problem. Good idea, though... big10p: But would that cause text to still display fine on another texture, and oval works on this texture, but not text... all 2d commands... |
| ||
Oh, so it works sometimes, but not always - on the same machine? That is odd. |
| ||
Text (and possibly other drawing commands) on textures isn't supported. You need to draw to the backbuffer and grab that to put on the texture. Or find some other method. Worth trying jfks solution here: http://www.blitzmax.com/Community/posts.php?topic=50559 |
| ||
Good call Beaker. I'm a bit rusty with B3D. :) |
| ||
big10p: No, it is always consistent on my machine (text and oval both display fine) and always consistent on my ex's machine (no text, but oval displays fine). Beaker: I think we're on to something. I will try drawing to backbuffer and copyrecting, as soon as I have access to my ex's pc (she and her baby are taking a nap. Damned inconvenient! :-) If that's the cause, it's utterly bizarre. Does this mean that a texture exist only in Direct3d, and is that why this happens? I realize textures exist in the graphics card, but isn't a blitz texture an object in regular memory first that is transferred to the graphics card? If so it would be a fixable bug in Blitz3d, but otherwise I can see how it might be unfixable. I'll post the results when I get them... |
| ||
TRY SOMTHING LIKE THIS.. IN THIS CODE YOU WOULD USE TEXT2() IN PLACE OF TEXT() Global INTELSUPPORT=1 Global INTEL_TEXTIMAGE_HIGH Global INTEL_TEXTIMAGE_MID Global INTEL_TEXTIMAGE_LOW Global INTEL_TEXTIMAGE_VERYLOW If intelsupport=1 Then Intel_TextImage_High=CreateImage(512,16) Intel_TextImage_Mid=CreateImage(256,16) Intel_TextImage_low=CreateImage(128,16) Intel_TextImage_verylow=CreateImage(64,16) EndIf Function inteL_Text(x,y,txt$) thisbuffer=GraphicsBuffer() oldr=ColorRed() oldg=ColorGreen() oldb=ColorBlue() stw=StringWidth (txt$) Color r,g,b ;-- If stw>256 Then SetBuffer ImageBuffer(intel_Textimage_high) Color 0,0,0 Rect 0,0,512,16,True Color oldr,oldg,oldb Text 0,0,txt$ SetBuffer thisbuffer CopyImage2 intel_Textimage_high,x,y,thisbuffer,StringWidth(txt$) ElseIf stw>128 SetBuffer ImageBuffer(intel_Textimage_mid) Color 0,0,0 Rect 0,0,256,16,True Color oldr,oldg,oldb Text 0,0,txt$ CopyImage2 intel_Textimage_mid,x,y,thisbuffer,StringWidth(txt$) ElseIf stw>64 SetBuffer ImageBuffer(intel_Textimage_low) Color 0,0,0 Rect 0,0,128,16,True Color oldr,oldg,oldb Text 0,0,txt$ CopyImage2 intel_Textimage_low,x,y,thisbuffer,StringWidth(txt$) Else SetBuffer ImageBuffer(intel_Textimage_verylow) Color 0,0,0 Rect 0,0,64,16,True Color oldr,oldg,oldb Text 0,0,txt$ CopyImage2 intel_Textimage_verylow,x,y,thisbuffer,StringWidth(txt$) EndIf ;-- SetBuffer BackBuffer() End Function Function Text2(x,y,txt$) If intelsupport=1 Then intel_text(x,y,txt$) Else Text x,y,txt$ EndIf End Function Function CopyImage2(temp_image,x1,y1,temp_buffer,strw=0) IMGW=STRW-1 If IMGW>(ImageWidth(TEMP_IMAGE)-1) Then IMGW=ImageWidth(TEMP_IMAGE)-1 IMGh=ImageHeight(TEMP_IMAGE)-1 For i=0 To IMGW For ii=0 To IMGH SetBuffer(ImageBuffer(temp_image)) ThisPixel=ReadPixel (i,ii) RCVAL=ThisPixel Shr 0 And 255 Shl 0 If rcval<>0 Then SetBuffer temp_buffer WritePixel x1+i,y1+ii,ThisPixel EndIf Next Next End Function Last edited 2010 |
| ||
Thanks RifRaf. Still waiting for an opportunity to test on the offending machine.. |
| ||
I had a short window to test and I was able to get text to appear on the texture using Rifraf's code. When I incorporated it into my actual program it made the whole gauge disappear, and then I ran out of time. I realize it's somehow the combination of alpha and text that triggers this. This is the only texture that has both. I'll test more tomorrow (using Rifraf's code and just copyrect from an image or backbuffer) and update here. Thanks again for all your help!!! -Pete |
| ||
Text (and possibly other drawing commands) on textures isn't supported. Quite true. However, I should add a precaution here. When you're running in 3D graphics mode, some graphics cards aren't even too fond of drawing text on the back buffer. The solution I came up with was to draw the text on an IMAGE, then draw that IMAGE onto the TEXTURE. Something like this: Graphics3D 800,600,0,2 Global MainCam = CreateCamera() Global MainLight = CreateLight() Global Cube = CreateCube() PositionEntity Cube, 0,0,5 ;ALWAYS REMEMBER TO USE FLAG 256 (store in VRAM) IF YOU'RE GOING TO DRAW ON A TEXTURE. ;Some graphics cards don't like drawing on a non-256-flagged texture, as I found out the hard way. Global CubeTex = CreateTexture(64,64,256) Global CubeTex_Buffer = CreateImage(64,64) EntityTexture Cube,CubeTex SetBuffer BackBuffer() While Not KeyHit(1) ;Draw the text on the "buffer" image SetBuffer ImageBuffer(CubeTex_Buffer) num = num + 1 Cls Color 255,255,255 Text 32,32,num,True,True SetBuffer TextureBuffer(CubeTex) Color 0,0,255 Rect 0,0,64,64 DrawImage CubeTex_Buffer,0,0 SetBuffer BackBuffer() TurnEntity Cube,.2,.4,.6 UpdateWorld RenderWorld Flip Wend End I tested this code on my machine, works perfectly. If it works for you, you'll see a blue cube with a number on each side counting up at the speed of light. XD |
| ||
Just my 2c: For future compatibility you better don't do any 2D commands on a texturebuffer, instead simply draw to the backbuffer, then copyrect to the texturebuffer. That's the fastest you can do that works on all machines. Last edited 2010 |
| ||
I had the exact same problem with my Arkanoid3D game. I tried writing text to a texture directly and it worked on my laptop (where I created the game), but it failed on my desktop pc (everything else was fine, except the text wasn't shown on the texture). I fixed it by using an image to draw the text on (in fact, create the entire texture on an image) and finally copyrect the image to the texture. That fixed the problem. The only drawback is that you're using alot more memory and that it takes a bit of time if you're using large textures (mine were only 32x32). |
| ||
super topic-revival : line 72 : the problem here come from the CreateTexture's flag "6" (2+4=alpha+masked) txt=CreateTexture(txtSize,txtSize,6) using Text won't work on most machines as long as you don't use 256 flag (VRam) txt=CreateTexture(txtSize,txtSize,2+4+256) should works like a charm. whatever, alpha or masked textures should be drawn using writepixel/writepixelfast, and not DirectDraw commands (that are not really made for this kind of codes). |
| ||
better late than never boby ! :) Last edited 2012 |