| Autor |
Beitrag |
kuhlthomas
      
Beiträge: 35
|
Verfasst: Mo 11.08.03 23:19
den folgenden quelltext habe ich unter anleitung eines tutorials erstellt eigendlich sollte ich beim programmstart ein quadrat sehen (ich sehe aber nur schwarz). nimmt sich jemand die zeit das mal durchzusehen?
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: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OpenGL12, AppEvnts, Textures;
type TForm1 = class(TForm) ApplicationEvents1: TApplicationEvents; procedure FormCreate(Sender: TObject); procedure InitGL; procedure DrawScene; procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean); private public end;
procedure SetDCPixelFormat(Handle: HDC);
var Form1: TForm1; h_DC: hDC; hRC: HGLRC;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject); begin InitOpenGL; h_DC:=GetDC(Handle); SetDCPixelFormat(h_DC); hRC:=wglCreateContext(h_DC); wglMakeCurrent(h_DC,hRC); Application.OnIdle := ApplicationEvents1Idle; end;
procedure SetDCPixelFormat(Handle: HDC); var nPixelFormat: GLUint; const pfd: PIXELFORMATDESCRIPTOR = ( nSize: sizeof( PIXELFORMATDESCRIPTOR ); nVersion: 1; dwFlags: PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER; iPixelType: PFD_TYPE_RGBA; cColorBits: 16; cRedBits: 0; cRedShift: 0; cGreenBits: 0; cBlueBits: 0; cBlueShift: 0; cAlphaBits: 0; cAlphaShift: 0; cAccumBits: 0; cAccumRedBits: 0; cAccumGreenBits: 0; cAccumBlueBits: 0; cAccumAlphaBits: 0; cDepthBits: 16; cStencilBits: 0; cAuxBuffers: 0; iLayerType: PFD_MAIN_PLANE; bReserved: 0; dwLayerMask: 0; dwVisibleMask: 0; dwDamageMask: 0 ); begin nPixelFormat:=ChoosePixelFormat(h_DC, @pfd); SetPixelFormat(h_DC,nPixelFormat,@pfd); end;
procedure TForm1.InitGL; begin glClearColor(0,0,0,0); glClearDepth(1); glDepthFunc(GL_LESS); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST);
glViewport(0,0,Width,Height); glMatrixMode(GL_PROJECTION); glLoadIdentity; gluPerspective(45,Width/Height,1,100); glMatrixMode(GL_MODELVIEW); end;
procedure TForm1.DrawScene; begin glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); glLoadIdentity; glBegin(GL_QUADS); glVertex3f(1,-1,-5); glVertex3f(1,1,-5); glVertex3f(-1,1,-5); glVertex3f(-1,-1,-5); glEnd; glTranslate(0,0,-5); glBegin(GL_QUADS); glColor3f(1,0,0); glVertex3f(1,-1,0); glColor3f(1,1,0); glVertex3f(1,1,0); glColor3f(0,1,0); glVertex3f(-1,1,0); glColor3f(0,0,1); glVertex3f(-1,-1,0); glEnd;
SwapBuffers(h_DC); end;
procedure TForm1.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean); begin DrawScene; Done:=False; end;
end. |
|
|
Mr_T
      
Beiträge: 73
Win XP, Fedora Core RC 1
|
Verfasst: Di 12.08.03 11:43
Also ich würde den Teufel hier suchen:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
| glBegin(GL_QUADS); glVertex3f(1,-1,-5); glVertex3f(1,1,-5); glVertex3f(-1,1,-5); glVertex3f(-1,-1,-5); glEnd; glTranslate(0,0,-5); glBegin(GL_QUADS); glColor3f(1,0,0); glVertex3f(1,-1,0); glColor3f(1,1,0); glVertex3f(1,1,0); glColor3f(0,1,0); glVertex3f(-1,1,0); glColor3f(0,0,1); glVertex3f(-1,-1,0); glEnd; |
Das Ding ist nämlich: so wie du es machst, wird das 2. Quad exact da gezeichnet, wo das erste Schon ist... Deshalb wird (Aufgrund des Tiefentestes) das 2. nicht gezeichnet... Das erste dürfte deshalb nicht zusehen sein, weil es keine Farbe zugewiesen bekommen hat... das heißt, normalerweise sollte es reichen, wenn du den Obrigen Codeschnipsel durch diesen ersetzt:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
| glTranslate(0,0,-5); glBegin(GL_QUADS); glColor3f(1,0,0); glVertex3f(1,-1,0); glColor3f(1,1,0); glVertex3f(1,1,0); glColor3f(0,1,0); glVertex3f(-1,1,0); glColor3f(0,0,1); glVertex3f(-1,-1,0); glEnd; |
PS: Ich vermisse in deiner Unit das "Onresize"-Ereigniss deiner Form... leg es mal an und Tippe diesen Code rein (Daran könnte es durchaus auch liegen...):
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9:
| procedure TForm1.FormResize(Sender: TObject); begin glViewport(0, 0, form1.clientWidth, form1.clientHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, form1.clientWidth/form1.clientHeight, 1, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); end; |
_________________ Es gibt 10 Arten Binäre Zahlen zu interpretieren: 0 und 1
Wer nicht kämpft, hat schon verloren!
|
|
kuhlthomas 
      
Beiträge: 35
|
Verfasst: Di 12.08.03 13:59
jawoll es lag am FormResize - jetzt klappts
danke!!
|
|
|