Долго искал свои исходники. Перерыл всю мою библиотеку сорцев. Не нашел. Зашел на NeHe по выше указаному линку. Докрутил страницу до конца, а там... Ба!
| Цитата | | * DOWNLOAD Delphi Code For This Lesson. |
Вот что значит внимательность.
lesson14.dpr
| Код | program lesson14;
// // This code was created by Jeff Molofee '99 // // If you've found this code useful, please let me know. // // Visit me at www.demonews.com/hosted/nehe // // Translation to Delphi by Marc Aarts ([email protected]) //
uses Windows, Messages, OpenGL;
{$R *.RES}
var h_RC : HGLRC; // Permanent Rendering Context h_DC : HDC; // Private GDI Device Context
keys : array [0..255] of BOOL; // Array Used For The Keyboard Routine
base : GLuint; // Base Display List For The Font Set rot : GLfloat; // Used To Rotate The Text
procedure BuildFont; // Build Our Bitmap Font var font: HFONT; // Windows Font ID gmf : array [0..255] of GLYPHMETRICSFLOAT; // Address Buffer For Font Storage begin base := glGenLists(256); // Storage For 96 Characters font := CreateFont(-12, // Height Of Font 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight 0, // Italic 0, // Underline 0, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE or DEFAULT_PITCH, // Family And Pitch 'Comic Sans MS'); // Font Name
SelectObject(h_DC, font); // Selects The Font We Want
wglUseFontOutlines( h_DC, // Select The Current DC 0, // Starting Character 255, // Number Of Display Lists To Build base, // Starting Display Lists 0.0, // Deviation From The True Outlines 0.2, // Font Thickness In The Z Direction WGL_FONT_POLYGONS, // Use Polygons, Not Lines @gmf); // Address Of Buffer To Recieve Data
end;
procedure KillFont; // Delete The Font begin glDeleteLists(base, 256); // Delete All 96 Characters end;
procedure glPrint(text : pchar); // Custom GL "Print" Routine begin if (text = '') then // If There's No Text Exit; // Do Nothing
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits glListBase(base); // Sets The Base Character glCallLists(length(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text glPopAttrib(); // Pops The Display List Bits end;
procedure InitGL(Width: GLsizei; Height: GLsizei); // This Will Be Called Right After The GL Window Is Created var fWidth, fHeight : GLfloat; begin glClearColor(0.0, 0.0, 0.0, 0.0); // Clear The Background Color To Black glClearDepth(1.0); // Enables Clearing Of The Depth Buffer glDepthFunc(GL_LESS); // The Type Of Depth Test To Do glEnable(GL_DEPTH_TEST); // Enables Depth Testing glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix // Reset The Projection Matrix
fWidth := Width; fHeight := Height; gluPerspective(45.0, fWidth/fHeight,0.1,100.0); // Calculate The Aspect Ratio Of The Window
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
BuildFont(); // Build The Font glEnable(GL_LIGHT0); // Enable Default Light (Quick And Dirty) glEnable(GL_LIGHTING); // Enable Lighting glEnable(GL_COLOR_MATERIAL); // Enable Coloring Of Material end;
procedure ReSizeGLScene(Width: GLsizei; Height: GLsizei); var fWidth, fHeight: GLfloat; begin if (Height=0) then Height:=1; // Prevent A Divide By Zero If The Window Is Too Small
glViewport(0, 0, Width, Height); // Reset The Current Viewport And Perspective Transformation
glMatrixMode(GL_PROJECTION); glLoadIdentity();
fWidth := Width; fHeight := Height; gluPerspective(45.0, fWidth/fHeight, 0.1, 100.0); glMatrixMode(GL_MODELVIEW); end;
procedure DrawGLScene(); begin glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The View glTranslatef(0.0,0.0,-10.0); // Move One Unit Into The Screen glRotatef(rot,1.0,0.0,0.0); // Rotate On The X Axis glRotatef(rot*1.2,0.0,1.0,0.0); // Rotate On The Y Axis glRotatef(rot*1.4,0.0,0.0,1.0); // Rotate On The Z Axis glTranslatef(-3.5,0.0,0.0); // Move To The Left Before Drawing // Pulsing Colors Based On The Rotation glColor3f(1.0*(cos(rot/20.0)),1.0*(sin(rot/25.0)),1.0-0.5*(cos(rot/17.0))); glPrint('OpenGL With NeHe'); // Print GL Text To The Screen glColor3f(0.0,0.0,1.0); // Make The Text Blue rot := rot + 0.1; // Increase The Rotation Variable end;
function WndProc(hWnd: HWND; message: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; var Screen: TRECT; PixelFormat: GLuint; const pfd: PIXELFORMATDESCRIPTOR = ( nSize: sizeof( PIXELFORMATDESCRIPTOR ); // Size Of This Pixel Format Descriptor nVersion: 1; // Version Number (?) dwFlags: PFD_DRAW_TO_WINDOW // Format Must Support Window or PFD_SUPPORT_OPENGL // Format Must Support OpenGL or PFD_DOUBLEBUFFER; // Must Support Double Buffering iPixelType: PFD_TYPE_RGBA; // Request An RGBA Format cColorBits: 16; // Select A 16Bit Color Depth cRedBits: 0; // Color Bits Ignored (?) cRedShift: 0; cGreenBits: 0; cBlueBits: 0; cBlueShift: 0; cAlphaBits: 0; // No Alpha Buffer cAlphaShift: 0; // Shift Bit Ignored (?) cAccumBits: 0; // No Accumulation Buffer cAccumRedBits: 0; // Accumulation Bits Ignored (?) cAccumGreenBits: 0; cAccumBlueBits: 0; cAccumAlphaBits: 0; cDepthBits: 16; // 16Bit Z-Buffer (Depth Buffer) cStencilBits: 0; // No Stencil Buffer cAuxBuffers: 0; // No Auxiliary Buffer (?) iLayerType: PFD_MAIN_PLANE; // Main Drawing Layer bReserved: 0; // Reserved (?) dwLayerMask: 0; // Layer Masks Ignored (?) dwVisibleMask: 0; dwDamageMask: 0 );
begin Result := 0; case (message) of // Tells Windows We Want To Check The Message WM_CREATE: begin h_DC := GetDC(hWnd); // Gets a Device Context For The Window PixelFormat := ChoosePixelFormat(h_DC, @pfd); // Finds The Closest Match To The Pixel Format We Set Above
if (PixelFormat=0) then begin MessageBox(0,'Cant''t Find A Suitable PixelFormat.','Error',MB_OK or MB_ICONERROR); PostQuitMessage(0); // This Sends A 'Message' Telling The Program To Quit exit; end;
if (not SetPixelFormat(h_DC,PixelFormat,@pfd)) then begin MessageBox(0,'Can''t Set The PixelFormat.','Error',MB_OK or MB_ICONERROR); PostQuitMessage(0); exit; end;
h_RC := wglCreateContext(h_DC); if (h_RC=0) then begin MessageBox(0,'Can''t Create A GL Rendering Context.','Error',MB_OK or MB_ICONERROR); PostQuitMessage(0); exit; end;
if (not wglMakeCurrent(h_DC, h_RC)) then begin MessageBox(0,'Can''t activate GLRC.','Error',MB_OK or MB_ICONERROR); PostQuitMessage(0); exit; end;
GetClientRect(hWnd, Screen); InitGL(Screen.right, Screen.bottom); end;
WM_DESTROY, WM_CLOSE: begin ChangeDisplaySettings(DEVMODE(nil^), 0);
wglMakeCurrent(h_DC,0); wglDeleteContext(h_RC); ReleaseDC(hWnd,h_DC);
PostQuitMessage(0); end;
WM_KEYDOWN: begin keys[wParam] := TRUE; end;
WM_KEYUP: begin keys[wParam] := FALSE; end;
WM_SIZE: begin ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); end;
else begin Result := DefWindowProc(hWnd, message, wParam, lParam); exit; end; end; end;
function WinMain(hInstance: HINST; hPrevInstance: HINST; lpCmdLine: PChar; nCmdShow: integer): integer; stdcall; var msg: TMsg; // Windows Message Structure wc: TWndClass; // Windows Class Structure Used To Set Up The Type Of Window h_Wnd: HWND; // Storage For Window Handle dmScreenSettings: DEVMODE;
begin ZeroMemory(@wc, SizeOf(wc));
wc.style := CS_HREDRAW or CS_VREDRAW or CS_OWNDC; wc.lpfnWndProc := @WndProc; wc.hInstance := hInstance; wc.hCursor := LoadCursor(0, IDC_ARROW); wc.lpszClassName := 'OpenGL WinClass';
if(RegisterClass(wc)=0) then begin MessageBox(0,'Failed To Register The Window Class.','Error',MB_OK or MB_ICONERROR); Result := 0; exit; end;
h_Wnd := CreateWindow( 'OpenGL WinClass', 'Jeff Molofee''s GL Code Tutorial ... NeHe 2000', // Title Appearing At The Top Of The Window WS_POPUP or WS_CLIPCHILDREN or WS_CLIPSIBLINGS, 0, 0, // The Position Of The Window On The Screen 640, 480, // The Width And Height Of The WIndow 0, 0, hInstance, nil );
if (h_Wnd = 0) then begin MessageBox(0,'Window Creation Error.','Error',MB_OK or MB_ICONERROR); Result := 0; exit; end;
ZeroMemory( @dmScreenSettings, sizeof( DEVMODE ) ); dmScreenSettings.dmSize := sizeof( DEVMODE ); dmScreenSettings.dmPelsWidth := 640; // Width dmScreenSettings.dmPelsHeight := 480; // Height dmScreenSettings.dmFields := DM_PELSWIDTH or DM_PELSHEIGHT; // Color Depth ChangeDisplaySettings(dmScreenSettings, CDS_FULLSCREEN); // Switch To Fullscreen Mode
ShowWindow(h_Wnd, SW_SHOW); UpdateWindow(h_Wnd); SetFocus(h_Wnd);
while (true) do begin // Process All Messages while (PeekMessage(msg, 0, 0, 0, PM_NOREMOVE)) do begin if (GetMessage(msg, 0, 0, 0)) then begin TranslateMessage(msg); DispatchMessage(msg); end else begin Result := 1; exit; end; end;
DrawGLScene(); SwapBuffers(h_DC);
if (keys[VK_ESCAPE]) then SendMessage(h_Wnd,WM_CLOSE,0,0); end; end;
begin WinMain( hInstance, hPrevInst, CmdLine, CmdShow ); end. |
Юзайте на здоровье. Я там полистал уроки. Почти ко всем (если не ко всем) есть сорци на Дэлфи. |