Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Mi Jul 16, 2025 05:47

Foren-Übersicht » Programmierung » OpenGL
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 9 Beiträge ] 
Autor Nachricht
BeitragVerfasst: Mi Aug 29, 2007 14:51 
Offline
DGL Member

Registriert: Mo Jul 17, 2006 13:16
Beiträge: 69
Hi!
Ich versuche gerade mit den SDL-Schriften klar zu kommen und habe dazu das Beispielprogramm modifiziert.
Leider kommt bei mir immer nur weisse Schrift auf nem hellblauen Hintergrund.

Ich brauche definiert-bunte Schrift ohne Hintergrund. Idealer Weise auch mit Farbverlaufmöglichkeiten, wie es mit normalen Texturen möglich ist.

Was ist hier falsch?

Referenzen: http://wiki.delphigl.com/index.php/TTF_Rendermode

Achtung: ich benutze TTF_RenderText_Blended !

Code:
  1. program glfont;
  2. {
  3.     glfont:  An example of using the SDL_ttf library with OpenGL.
  4.     Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.     You should have received a copy of the GNU Library General Public
  14.     License along with this library; if not, write to the Free
  15.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  16.     The SDL_GL_* functions in this file are available in the public domain.
  17.     Sam Lantinga
  18. }
  19. { $Id: glfont.dpr,v 1.1 2004/02/16 22:16:40 savage Exp $ }
  20. { A simple program to test the text rendering feature of the TTF library }
  21. uses
  22.   SysUtils,
  23.   sdl,
  24.   sdl_ttf,
  25.   gl;
  26.  
  27. (* Undefine this if you want a flat cube instead of a rainbow cube *)
  28. {$DEFINE SHADED_CUBE}
  29.  
  30. const
  31.   DEFAULT_PTSIZE = 200;
  32.   DEFAULT_TEXT = '1234567890000000000';
  33.   NUM_COLORS = 256;
  34.   Usage = 'Usage: %s <font>.ttf [-solid] [-utf8 or -unicode] [-b] [-i] [-u] [-fgcol r g b] [-bgcol r g b]  [-ptsize nn] [-text "message"]';
  35.   SCREEN_WIDTH = 640;
  36.   SCREEN_HEIGHT = 480;
  37.   SCREEN_BPP = 0;
  38.  
  39. procedure ShutDownApplication( HaltStatus : integer );
  40. begin
  41.   TTF_Quit;
  42.   SDL_Quit;
  43.   Halt( HaltStatus );
  44. end;
  45.  
  46. procedure SDL_GL_Enter2DMode;
  47. var
  48.   screen : PSDL_Surface;
  49. begin
  50.   screen := SDL_GetVideoSurface;
  51.   (* Note, there may be other things you need to change,
  52.      depending on how you have your OpenGL state set up.
  53.   *)
  54.   glPushAttrib( GL_ENABLE_BIT );
  55.   glDisable( GL_DEPTH_TEST );
  56.   glDisable( GL_CULL_FACE );
  57.   glEnable( GL_TEXTURE_2D );
  58.   glViewport( 0, 0, screen.w, screen.h );
  59.   glMatrixMode( GL_PROJECTION );
  60.   glPushMatrix;
  61.   glLoadIdentity;
  62.   glOrtho( 0.0, screen.w, screen.h, 0.0, 0.0, 1.0 );
  63.   glMatrixMode( GL_MODELVIEW );
  64.   glPushMatrix;
  65.   glLoadIdentity;
  66.   glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
  67. end;
  68.  
  69. procedure SDL_GL_Leave2DMode;
  70. begin
  71.   glMatrixMode( GL_MODELVIEW );
  72.   glPopMatrix;
  73.   glMatrixMode( GL_PROJECTION );
  74.   glPopMatrix;
  75.   glPopAttrib;
  76. end;
  77. (* Quick utility function for texture creation *)
  78.  
  79. function power_of_two( input : integer ) : integer;
  80. var
  81.   value : integer;
  82. begin
  83.   value := 1;
  84.   while ( value < input ) do
  85.   begin
  86.     value := value shl 1;
  87.   end;
  88.   result := value;
  89. end;
  90.  
  91. function SDL_GL_LoadTexture( surface : PSDL_Surface; var texcoord : array of GlFloat ) : GLuint;
  92. var
  93.   texture : GLuint;
  94.   w, h : integer;
  95.   image : PSDL_Surface;
  96.   area : TSDL_Rect;
  97.   saved_flags : Uint32;
  98.   saved_alpha : Uint8;
  99. begin
  100.   (* Use the surface width and height expanded to powers of 2 *)
  101.   w := power_of_two( surface.w );
  102.   h := power_of_two( surface.h );
  103.   texcoord[ 0 ] := 0.0; (* Min X *)
  104.   texcoord[ 1 ] := 0.0; (* Min Y *)
  105.   texcoord[ 2 ] := surface.w / w; (* Max X *)
  106.   texcoord[ 3 ] := surface.h / h; (* Max Y *)
  107.   image := SDL_CreateRGBSurface(
  108.     SDL_SWSURFACE,
  109.     w, h,
  110.     32,
  111. {$IFDEF IA32} (* OpenGL RGBA masks *)
  112.     $000000FF,
  113.     $0000FF00,
  114.     $00FF0000,
  115.     $FF000000
  116. {$ELSE}
  117.     $FF000000,
  118.     $00FF0000,
  119.     $0000FF00,
  120.     $000000FF
  121. {$ENDIF}
  122.     );
  123.   if ( image = nil ) then
  124.   begin
  125.     result := 0;
  126.     exit;
  127.   end;
  128.   (* Save the alpha blending attributes *)
  129.   saved_flags := surface.flags and ( SDL_SRCALPHA or SDL_RLEACCELOK );
  130.   saved_alpha := surface.format.alpha;
  131.   if ( ( saved_flags and SDL_SRCALPHA ) = SDL_SRCALPHA ) then
  132.   begin
  133.     SDL_SetAlpha( surface, 0, 0 );
  134.   end;
  135.   (* Copy the surface into the GL texture image *)
  136.   area.x := 0;
  137.   area.y := 0;
  138.   area.w := surface.w;
  139.   area.h := surface.h;
  140.   SDL_BlitSurface( surface, @area, image, @area );
  141.   (* Restore the alpha blending attributes *)
  142.   if ( ( saved_flags and SDL_SRCALPHA ) = SDL_SRCALPHA ) then
  143.   begin
  144.     SDL_SetAlpha( surface, saved_flags, saved_alpha );
  145.   end;
  146.   (* Create an OpenGL texture for the image *)
  147.   glGenTextures( 1, @texture );
  148.   glBindTexture( GL_TEXTURE_2D, texture );
  149.   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
  150.   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  151.   glTexImage2D( GL_TEXTURE_2D,
  152.     0,
  153.     GL_RGBA,
  154.     w, h,
  155.     0,
  156.     GL_RGBA,
  157.     GL_UNSIGNED_BYTE,
  158.     image.pixels );
  159.   SDL_FreeSurface( image ); (* No longer needed *)
  160.   result := texture;
  161. end;
  162.  
  163. type
  164.   TRenderType = ( rtLatin1, rtUTF8, rtUnicode );
  165.  
  166. var
  167.   //fontfile : string;
  168.   gl_error : GLenum;
  169.   texture : GLuint;
  170.   x, y, w, h : integer;
  171.   //texcoord : array[ 0..4 ] of TGLfloat;
  172.   texMinX, texMinY : GLfloat;
  173.   texMaxX, texMaxY : GLfloat;
  174.   color : array[ 0..7, 0..2 ] of single = ( ( 1.0, 1.0, 0.0 ),
  175.     ( 1.0, 0.0, 0.0 ),
  176.     ( 0.0, 0.0, 0.0 ),
  177.     ( 0.0, 1.0, 0.0 ),
  178.     ( 0.0, 1.0, 1.0 ),
  179.     ( 1.0, 1.0, 1.0 ),
  180.     ( 1.0, 0.0, 1.0 ),
  181.     ( 0.0, 0.0, 1.0 ) );
  182.   cube : array[ 0..7, 0..2 ] of single = ( ( 0.5, 0.5, -0.5 ),
  183.     ( 0.5, -0.5, -0.5 ),
  184.     ( -0.5, -0.5, -0.5 ),
  185.     ( -0.5, 0.5, -0.5 ),
  186.     ( -0.5, 0.5, 0.5 ),
  187.     ( 0.5, 0.5, 0.5 ),
  188.     ( 0.5, -0.5, 0.5 ),
  189.     ( -0.5, -0.5, 0.5 ) );
  190.   screen : PSDL_Surface = nil;
  191.   font : PTTF_Font;
  192.   temp : PSDL_Surface = nil;
  193.   ptsize : integer = 0;
  194.   i : integer;
  195.   done : Boolean = false;
  196.   //rdiff, gdiff, bdiff : integer;
  197.   //colors : array[ 0..NUM_COLORS - 1 ] of TSDL_Color;
  198.   white : TSDL_Color = ( r : $FF; g : $FF; b : $FF; unused : 0 );
  199.   black : TSDL_Color = ( r : $00; g : $00; b : $00; unused : 0 );
  200.   bla : TSDL_Color = ( r : $FF; g : $00; b : $00; unused : 0 );
  201.   forecol : TSDL_Color;
  202.   backcol : TSDL_Color;
  203.   //dstrect : TSDL_Rect;
  204.   event : TSDL_Event;
  205.   rendersolid : Boolean = false;
  206.   renderstyle : integer = TTF_STYLE_NORMAL;
  207.   rendertype : TRenderType = rtLatin1;
  208.   dump : Boolean;
  209.   message : string;
  210.   glyph : PSDL_Surface = nil;
  211.   r, g, b : integer;
  212.   outname : string;
  213.   //texcoord : array[ 0..3 ] of TGLfloat;
  214.   aspect : single;
  215.  
  216. procedure DrawTextTexture;
  217. var
  218.   //screen : PSDL_Surface;
  219.   image : PSDL_Surface;
  220.   texcoord : array[ 0..3 ] of GlFloat;
  221. begin
  222.   if ( texture = 0 ) then begin
  223.      image := TTF_RenderText_Blended( font, PChar( message ), white);
  224.     w := image.w;
  225.     h := image.h;
  226.     (* Convert the image into an OpenGL texture *)
  227.     texture := SDL_GL_LoadTexture( image, texcoord );
  228.     (* Make texture coordinates easy to understand *)
  229.     texMinX := texcoord[ 0 ];
  230.     texMinY := texcoord[ 1 ];
  231.     texMaxX := texcoord[ 2 ];
  232.     texMaxY := texcoord[ 3 ];
  233.     (* We don't need the original image anymore *)
  234.     SDL_FreeSurface( image );
  235.     (* Make sure that the texture conversion is okay *)
  236.     if ( texture = 0 ) then
  237.     begin
  238.       exit;
  239.     end;
  240.   end;
  241.  
  242.   (* Show the image on the screen *)
  243.   SDL_GL_Enter2DMode;
  244.   glBindTexture( GL_TEXTURE_2D, texture );
  245.   glBegin( GL_TRIANGLE_STRIP );
  246. //    glColor3f(1, 0, 0);
  247.     glTexCoord2f( texMinX, texMinY );
  248.     glVertex2i( x, y );
  249. //    glColor3f(1, 1, 0);
  250.     glTexCoord2f( texMaxX, texMinY );
  251.     glVertex2i( x + w, y );
  252. //    glColor3f(0, 1, 0);
  253.     glTexCoord2f( texMinX, texMaxY );
  254.     glVertex2i( x, y + h );
  255. //    glColor3f(0, 1, 1);
  256.     glTexCoord2f( texMaxX, texMaxY );
  257.     glVertex2i( x + w, y + h );
  258.   glEnd;
  259.   SDL_GL_Leave2DMode;
  260. end;
  261.  
  262. begin
  263.   ptsize := 76;
  264.  
  265.   { Initialize SDL }
  266.   if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) then SDL_Quit;
  267.   { Initialize the TTF library }
  268.   if ( TTF_Init < 0 ) then SDL_Quit;
  269.  
  270.   font := TTF_OpenFont( PChar( ParamStr( 1 ) ), ptsize );
  271.  
  272.   TTF_SetFontStyle( font, renderstyle );
  273.  
  274.   screen := SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL );
  275.  
  276.   { Render and center the message }
  277.   if ( message = '' ) then
  278.   begin
  279.     message := DEFAULT_TEXT;
  280.   end;
  281.  
  282.   { Wait for a keystroke, and blit text on mouse press }
  283.   done := false;
  284.   while ( not done ) do
  285.   begin
  286.     while ( SDL_PollEvent( @event ) <> 0 ) do
  287.     begin
  288.       case event.type_ of
  289.         SDL_MOUSEBUTTONDOWN :
  290.           begin
  291.             x := event.motion.x - w div 2;
  292.             y := event.motion.y - h div 2;
  293.           end;
  294.  
  295.         SDL_KEYDOWN, SDL_QUITEV :
  296.           begin
  297.             done := true;
  298.           end;
  299.       end;
  300.     end;
  301.  
  302.   { Clear the screen }
  303.   glClearColor( 0.5, 0.5, 0.5, 1.0 );
  304.   glClear( GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT );
  305.   { Draw the spinning cube }
  306.  
  307.   // Referenz-Hintergrund
  308.   glBegin(GL_Quads);
  309.     glColor3f(1, 0, 0); glVertex3f(-1,-1, 0);
  310.     glColor3f(0, 0, 1); glVertex3f( 1,-1, 0);
  311.     glColor3f(0, 1, 0); glVertex3f( 1, 1, 0);
  312.     glColor3f(0, 1, 0); glVertex3f( -1, 1, 0);
  313.   glEnd;
  314.  
  315.  //Alphatest
  316.   glEnable(GL_ALPHA_TEST);
  317.   glAlphaFunc(GL_GREATER, 1);
  318.   glAlphaFunc(GL_GREATER, 0.4);
  319.   glColor3f(0,0,0);
  320.   DrawTextTexture;
  321.   glDisable(GL_ALPHA_TEST);
  322.   //Blenden
  323.   glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  324.   glEnable(GL_BLEND);
  325.   glColor3f(1,1,1);
  326.   DrawTextTexture;
  327.   glDisable(GL_BLEND);
  328.  
  329.   SDL_GL_SwapBuffers;
  330.   end;
  331.   TTF_CloseFont( font );
  332.   ShutDownApplication( 0 );
  333. end.
  334.  


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Aug 29, 2007 15:02 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 05, 2002 10:35
Beiträge: 4234
Wohnort: Dortmund
Es gab mal einen Fehler in dem SDL Header. Dadurch wurden wohl die Farbkanäle vertauscht und ich meine der hat sich Haar genau so geäußerst. Der Header aus dem DGL-SDK sind in der Sache berichtigt.

Könnte aber auch an dieser Stelle liegen. (Vermutung)
Code:
  1. {$IFDEF IA32} (* OpenGL RGBA masks *)
  2.   $000000FF,
  3.   $0000FF00,
  4.   $00FF0000,
  5.   $FF000000
  6. {$ELSE}
  7.   $FF000000,
  8.   $00FF0000,
  9.   $0000FF00,
  10.   $000000FF
  11. {$ENDIF}


Aber etwas ganz Anderes. *hust* Um mal ein bisschen Werbung zu machen. Schau mal das Thema da. ;)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Aug 30, 2007 10:14 
Offline
DGL Member

Registriert: Mo Jul 17, 2006 13:16
Beiträge: 69
Wenn man anstatt der Compilerbedingungen einfach
Code:
  1.  
  2. $FF000000,
  3. $00FF0000,
  4. $0000FF00,
  5. $000000FF


schreibt, stimmt zumindest die Schriftfarbe. Der Hintergrund verhält sich nach wie vor merkwürdig.

Ich versuche nun Lossy's TextSuite, hänge da aber atm auch:
viewtopic.php?p=56673#56673


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Aug 30, 2007 11:18 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 05, 2002 10:35
Beiträge: 4234
Wohnort: Dortmund
Die Klassische RGBA Maske ist normal aber
Code:
  1. $000000FF
  2. $0000FF00
  3. $00FF0000
  4. $FF000000
  5.  


Denn Rot ist das niederste Byte, Grün das Zweite usw.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Aug 30, 2007 12:01 
Offline
Ernährungsberater
Benutzeravatar

Registriert: Sa Jan 01, 2005 17:11
Beiträge: 2068
Programmiersprache: C++
Übrigens befindet sich im DGLSDK die easySDLFont welche auch Schriften über SDL_TTF erstellt.
Gib mal die Version deiner Header (sdl_ttf.pas sowie jedi*.inc) und der DLLs.

_________________
Steppity,steppity,step,step,step! :twisted:
❆ ❄ ❄ ❄ ❅ ❄ ❆ ❄ ❅ ❄ ❅ ❄ ❅ ❄ ❄
❄ ❄ ❄ ❅ ❄ ❄ ❄ ❅ ❄ ❄ ❆ ❄ ❄


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Aug 30, 2007 13:07 
Offline
DGL Member

Registriert: Mo Jul 17, 2006 13:16
Beiträge: 69
Alle Dateien kommen von dglsdk_2006.1.exe

$Id: sdl.pas,v 1.24 2006/05/18 21:10:04 savage Exp $

$Id: sdl_ttf.pas,v 1.10 2005/01/02 19:07:32 savage Exp $

$Id: gl.pas,v 1.2 2004/08/14 22:54:30 savage Exp $


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Aug 30, 2007 16:41 
Offline
Ernährungsberater
Benutzeravatar

Registriert: Sa Jan 01, 2005 17:11
Beiträge: 2068
Programmiersprache: C++
jedi-sdl.inc?

_________________
Steppity,steppity,step,step,step! :twisted:
❆ ❄ ❄ ❄ ❅ ❄ ❆ ❄ ❅ ❄ ❅ ❄ ❅ ❄ ❄
❄ ❄ ❄ ❅ ❄ ❄ ❄ ❅ ❄ ❄ ❆ ❄ ❄


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Aug 30, 2007 17:27 
Offline
DGL Member

Registriert: Mo Jul 17, 2006 13:16
Beiträge: 69
$Id: jedi-sdl.inc,v 1.9 2004/12/23 23:42:17 savage Exp $


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Aug 30, 2007 17:33 
Offline
Ernährungsberater
Benutzeravatar

Registriert: Sa Jan 01, 2005 17:11
Beiträge: 2068
Programmiersprache: C++
Lossy eX hat geschrieben:
Es gab mal einen Fehler in dem SDL Header. Dadurch wurden wohl die Farbkanäle vertauscht und ich meine der hat sich Haar genau so geäußerst. Der Header aus dem DGL-SDK sind in der Sache berichtigt.
...

Genau das ist es:
Zitat:
Revision 1.11 2006/01/04 00:52:41 drellis
Updated to include defined for ENDIAN values, SDL_BYTEORDER should now be correctly defined depending onthe platform. Code taken from sdl_mixer

Fehlt nämlich in deiner jedi-sdl.inc.
Aktuelle Version findest du im Jedi CVS oder DGLSDK-SVN.

_________________
Steppity,steppity,step,step,step! :twisted:
❆ ❄ ❄ ❄ ❅ ❄ ❆ ❄ ❅ ❄ ❅ ❄ ❅ ❄ ❄
❄ ❄ ❄ ❅ ❄ ❄ ❄ ❅ ❄ ❄ ❆ ❄ ❄


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 9 Beiträge ] 
Foren-Übersicht » Programmierung » OpenGL


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 9 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.011s | 16 Queries | GZIP : On ]