drawtext() et spriteoutput()

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
blendman
Messages : 2017
Inscription : sam. 19/févr./2011 12:46

drawtext() et spriteoutput()

Message par blendman »

salut

J'ai l'impression qu'il y a un bug avec un loadsprite, spriteoutput() et drawtext, ou je m'y prends comme une quiche ? :D

Voici un code comparatif entre un createsprite() et un loadsprite(), on voit le problème. Comment éviter les contours blancs sur les textes ?

Code : Tout sélectionner

#window = 0
Enumeration 
  #sprite 
  #sprite_load 
  #spriteFond
EndEnumeration

If InitSprite() = 0 Or InitMouse() = 0 Or  InitKeyboard() = 0 Or InitSprite3D() = 0 Or UsePNGImageDecoder() = 0
  End 
EndIf


If OpenWindow(#window, 0, 0, 640, 480, "affichage texte", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If OpenWindowedScreen(WindowID(0),0,0, 640, 480, 1, 0, 0)
  Else
    End
  EndIf
Else
  End  
EndIf

ShowCursor_(1)
Texte$= "Hello, voici un texte à lire, pour voir "
t2$ = "les quelques bugs liés à l'affichage"




; texte sur loadsprite
If LoadSprite(#sprite_load,"transparent_png.png",#PB_Sprite_Texture|#PB_Sprite_AlphaBlending)
  If CreateSprite3D(#sprite_load,#sprite_load)
    
    
    LoadFont(0,"arial.ttf",12,#PB_Font_Bold)
    
    If StartDrawing(SpriteOutput(#sprite_load))
      DrawingMode(#PB_2DDrawing_AlphaChannel)
      Box(0,0,SpriteWidth(#sprite_load),SpriteHeight(#sprite_load),RGBA(255,255,255,0))
      DrawingMode(#PB_2DDrawing_Transparent) 
      DrawText(0, 0, Texte$, $FF)
      DrawingFont(FontID(0))
      DrawText(0, 90, Texte$, $A81A0F); <----------------- autre bug lié au texte sur toutes les couleurs
      DrawText(0, 15, t2$, #Red); <----------------- autre bug lié au texte
      DrawText(0,40, Str(TextWidth(Texte$)));<--------------------- bug d'alpha sur les texte avec du blanc rgb(255,255,255)
      DrawText(0,60, Str(TextWidth(Texte$)),RGB(254,254,254))
      StopDrawing()
    EndIf
  EndIf
EndIf

; texte sur  createsprite 
If CreateSprite(#sprite, 300,400,#PB_Sprite_Texture|#PB_Sprite_AlphaBlending)
  CreateSprite3D(#sprite,#sprite)
  
  If StartDrawing(SpriteOutput(#sprite))
    DrawingMode(#PB_2DDrawing_AlphaChannel) 
    Box(0,0,300,400,RGBA(255,2552,255,0))
    DrawingMode(#PB_2DDrawing_Transparent) 
    DrawText(0, 0, Texte$, $FF)
    DrawText(0, 15, t2$, #Red)
    DrawText(0,40, Str(TextWidth(Texte$)));<--------------------- bug d'alpha sur les texte avec du blanc rgb(255,255,255)
    DrawText(0,60, Str(TextWidth(Texte$)),RGB(254,254,254))
    StopDrawing()
  EndIf
EndIf

; le fond (pour effacer le screen
If CreateSprite(#spriteFond, 640,480,#PB_Sprite_Texture|#PB_Sprite_AlphaBlending)
  If CreateSprite3D(#spriteFond,#spriteFond)
    
    If StartDrawing(SpriteOutput(#spriteFond))
      Box(0,0,SpriteWidth(#spriteFond),SpriteHeight(#spriteFond),RGB(125,125,125))
      StopDrawing()
    EndIf
  EndIf
EndIf

Repeat
  
  Event = WaitWindowEvent(50)
  ExamineKeyboard()
  ClearScreen(RGB(125,125,125))
  Start3D()
  DisplaySprite3D(#spriteFond,0,0)
  DisplaySprite3D(#sprite,10,50)
  DisplaySprite3D(#sprite_load,320,50)
  Stop3D()
  FlipBuffers()
  
Until Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
L'image à utiliser :
http://blendman.free.fr/dev/pb/bug/transparent_png.png

C'est une image complétement transparente, mais le problème est le même avec une image sans canal alpha, puisque j'efface l'image avant d'écran dessus.

Pour info, je ne peux pas me servir de createsprite(), car ça plante sur certains ordinateurs.
Désolé pour le code pourri, mais c'est juste pour montrer le problème vite fait :)
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: drawtext() et spriteoutput()

Message par Le Soldat Inconnu »

Salut,

Je ne pense pas qu'il soit possible de dessiner sur un sprite texturé (ou sprite 3D). c'est pour ça que tu as un contour blanc autour du texte, la gestion de la couche alpha ne fonctionne pas.

Extrait de l'aide :

Code : Tout sélectionner

Renvoie l'OutputID du #Sprite nécessaire à StartDrawing() pour effectuer les dessins 2D directement sur le #Sprite. 

Note: Il n'est pas possible d'utiliser SpriteOutput() (et par conséquent les fonctions de dessin 2D) avec un sprite du type #PB_Sprite_Alpha
En clair, tu ne pas dessiner sur ton sprite 3D
Il faut modifier l'image avnt de la charger en tant que sprite texturé avec couche alpha. Donc il faut passer par un fichier image temporaire.
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Répondre