| Autor |
Beitrag |
Bergmann89
      
Beiträge: 1742
Erhaltene Danke: 72
Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
|
Verfasst: So 07.12.08 18:13
HI,
ich hab grad irgendwie n Blackout oder so, auf jedenfall will es nich so wie ich will. Ich bin grad dabei n Game zu proggen und hab folgenedes Problem: Ich hab ne Klasse TMainMenu und die hat ne Variable HUD: THUD; das HUD is aber überflüssig, da es nur 2 Schriftzüge ausgibt und da wollt ich das gleich mit ins TMainMenu schreiben, aber wenn ich alles 1 zu 1 kopier gehts net?! Hier ma der relevante Code:
Das ist THUD:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85:
| type THUD = class private fFontContextID: TFontContextID; fViewport: TGLVectori4; fPointFont, fLiveFont: TFont; public procedure Render(Points, Live: Integer); constructor Create(FontContextID: TFontContextID); destructor Destroy; override; end;
implementation
procedure THUD.Render(Points, Live: Integer);
function FillString(Str: String; FillChar: Char; StrLength: Integer): String; var i: Integer; begin result := Str; for i := Length(result) to StrLength do result := FillChar + result; end;
begin glMatrixMode(GL_PROJECTION); glPushMatrix; glLoadIdentity; glOrtho(0,fViewport[2],fViewport[3],0,0,10); glMatrixMode(GL_MODELVIEW); glDisable(GL_DEPTH_TEST);
fPointFont.TextOut('Points: '+FillString(IntToStr(Points),'0',10), fViewport[2]* 1/100, fViewport[3]* 1/100, fViewport[2]*48/100, fViewport[3]*10/100, TS_ALIGN_LEFT);
fLiveFont.TextOut('Live: '+FillString(IntToStr(Live),'0',2), fViewport[2]*50/100, fViewport[3]* 1/100, fViewport[2]*49/100, fViewport[3]*10/100, TS_ALIGN_RIGHT);
glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glPopMatrix; glMatrixMode(GL_MODELVIEW); end;
constructor THUD.Create(FontContextID: TFontContextID); var Color: TVector4f; begin inherited Create;
glGetIntegerv(GL_VIEWPORT, @fViewport);
fFontContextID := FontContextID;
Color[0] := 1; Color[1] := 1; Color[2] := 1; Color[3] := 1;
fPointFont := TFont.Create(fFontContextID, TS_STYLE_NORMAL, round(fViewport[3]*5/100), ExtractFilePath(Application.ExeName)+'LCD_FONT.ttf', Color);
fLiveFont := TFont.Create(fFontContextID, TS_STYLE_NORMAL, round(fViewport[3]*5/100), ExtractFilePath(Application.ExeName)+'LCD_FONT.ttf', Color); end;
destructor THUD.Destroy; begin fPointFont.Destroy; fLivefont.Destroy; inherited Destroy; end; |
und das hab ich dann so in TMainMenu übernommen:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49:
| procedure TMainMenu.Render; [...] begin [..]
HUD.Render(6543215,100); glMatrixMode(GL_PROJECTION); glPushMatrix; glLoadIdentity; glOrtho(0,fViewport[2],fViewport[3],0,0,10); glMatrixMode(GL_MODELVIEW); glDisable(GL_DEPTH_TEST);
MenuFont.TextOut('Hallo^^', fViewport[2]* 1/100, fViewport[3]* 1/100, fViewport[2]*48/100, fViewport[3]*10/100, TS_ALIGN_LEFT);
glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glPopMatrix; glMatrixMode(GL_MODELVIEW); end;
constructor TMainMenu.Create(FontContextID: TFontContextID); [...] var Color: TVector4f; begin inherited Create;
fFontContextID := FontContextID; HUD := THUD.Create(fFontContextID);
glGetIntegerv(GL_VIEWPORT, @fViewport); Color[0] := 1; Color[1] := 1; Color[2] := 1; Color[3] := 1; MenuFont := TFont.Create(fFontContextID, TS_STYLE_NORMAL, round(fViewport[3]*5/100), ExtractFilePath(Application.ExeName)+'LCD_FONT.ttf', Color); [...] end; |
TFont is auch ne Klasse die ich selbst geschrieben hab, aber die geht, weil ja in der HUD-Klasse die Strings ausgegeben werden! Hab ich hier irgendwo n Fehler drin, den ich jetzt nich seh?
MfG Bergmann.
_________________ Ich weiß nicht viel, lern aber dafür umso schneller^^
|
|
jaenicke
      
Beiträge: 19346
Erhaltene Danke: 1754
W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
|
Verfasst: So 07.12.08 18:40
Was geht denn nicht? Passiert nix, kommt ein Fehler beim Kompilieren, beim Ausführen?
Was mir auffällt (aber vermutlich hier nicht das Problem ist) ist, dass du Klassennamen verwendest, die es im Standarddelphi gibt (TMainMenu, TFont, ...). Sowas ist keine gute Idee.
|
|
Bergmann89 
      
Beiträge: 1742
Erhaltene Danke: 72
Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
|
Verfasst: So 07.12.08 18:42
Es passiert nix...
das es ein TMainMenu gibt wusste ich gar nich(^^), aber wenn dass das Problem wäre, dann würde ja der Font im THUD nich gehen!
_________________ Ich weiß nicht viel, lern aber dafür umso schneller^^
|
|
|