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: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283:
| program OpenGLTest;
uses Windows, Messages, OpenGL, Textures, Tools in '..\..\..\..\Units\Tools.pas';
const ClassName = 'OpenGL WinClass'; AppName = 'Koshigaya Studios - OpenGL Test'; WindowWidth = 640; WindowHeight = 480;
var h_DC: hDC; h_RC: HGLRC; Rotate:Single; Go: Array[0..255] of Boolean; Tex: GLUInt; MoveLR: Single;
procedure glBindTexture(target: GLenum; texture: GLuint); stdcall; external opengl32;
procedure DrawScene; begin glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); glLoadIdentity;
// glColor3ub(255,255,0); bei glBegin //Code here!
// glTranslate(0,0,-5);
glScale(30,30,30); // glRotate(Rotate,1,0,0); glTranslate(0,0,Rotate/100); glTranslate(MoveLR,0,Rotate/100); glTranslate(0,Rotate/3,0);
glBindTexture(GL_TEXTURE_2D,Tex);
glBegin(GL_QUADS); glTexCoord2f(5,5); glVertex3f(1,1,1); glTexCoord2f(5,0); glVertex3f(1,-1,1); glTexCoord2f(0,0); glVertex3f(-1,-1,1); glTexCoord2f(0,5); glVertex3f(-1,1,1); glEnd;
glBegin(GL_QUADS); glTexCoord2f(5,5); glVertex3f(-1,-1,1); glTexCoord2f(5,0); glVertex3f(-1,1,1); glTexCoord2f(0,0); glVertex3f(-1,1,-1); glTexCoord2f(0,5); glVertex3f(-1,-1,-1); glEnd;
glBegin(GL_QUADS); glTexCoord2f(5,5); glVertex3f(1,1,-1); glTexCoord2f(5,0); glVertex3f(1,-1,-1); glTexCoord2f(0,0); glVertex3f(-1,-1,-1); glTexCoord2f(0,5); glVertex3f(-1,1,-1); glEnd;
glBegin(GL_QUADS); glTexCoord2f(5,5); glVertex3f(1,-1,1); glTexCoord2f(5,0); glVertex3f(1,1,1); glTexCoord2f(0,0); glVertex3f(1,1,-1); glTexCoord2f(0,5); glVertex3f(1,-1,-1); glEnd;
glBegin(GL_QUADS); glTexCoord2f(5,5); glVertex3f(1,-1,1); glTexCoord2f(5,0); glVertex3f(-1,-1,1); glTexCoord2f(0,0); glVertex3f(-1,-1,-1); glTexCoord2f(0,5); glVertex3f(1,-1,-1); glEnd;
glBegin(GL_QUADS); glTexCoord2f(5,5); glVertex3f(1,1,1); glTexCoord2f(5,0); glVertex3f(-1,1,1); glTexCoord2f(0,0); glVertex3f(-1,1,-1); glTexCoord2f(0,5); glVertex3f(1,1,-1); glEnd; end;
procedure InitGL; begin // hinter grund farhbe besteimmen glClearColor(0.5 , 0 , 0 , 0); // Tifenbuffer löschen glClearDepth(1.0); // Bestimmt die Tife funktione glDepthFunc(GL_LESS); // Tiefen testen abschalten glEnable(GL_DEPTH_TEST); // Wie sauber er zeichnen soll glShadeModel(GL_SMOOTH); // wo soll er zeichnen glMatrixMode(GL_PROJECTION); // Setzt alles zurück z.B glLoadIdentity; // Winkel gluPerspective(45.0, WindowWidth/WindowHeight,0.1,100.0); glMatrixMode(GL_MODELVIEW);
// Licht einstellungen // glEnable(GL_LIGHT0); // glEnable(GL_LIGHTING); // glEnable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_2D); LoadTexture(GetExeDir + 'Wall.bmp',Tex) end;
procedure ResizeGL(Width, Height: Integer); begin glViewport(0,0,Width,Height); glMatrixMode(GL_PROJECTION); glLoadIdentity; gluPerspective(45.0,Width/Height,0.1,100.0); glMatrixMode(GL_MODELVIEW); 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;
// fenster erstellen function WndProc(hWnd: HWND; message: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; var MouseX,MouseY:Integer; begin Result:=0; Case message of WM_CREATE: begin h_DC:=GetDC(hWnd); SetDCPixelFormat(h_DC); h_RC:=wglCreateContext(h_DC); wglMakeCurrent(h_DC,h_RC); InitGL; end;
WM_MOUSEMOVE: begin MouseX:=LoWord(lParam); MouseY:=HiWord(lParam); Rotate:=MouseY / 100; if MouseY < 20 then SetCursorPos(WindowWidth div 2,WindowHeight div 2) 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 Go[wParam]:=true; end; WM_KEYUP: begin Go[wParam]:=false; end; WM_SIZE: begin ResizeGL(LOWORD(lParam),HIWORD(lParam)); end; else begin Result:=DefWindowProc(hWnd,message,wParam,lParam); exit; end; end; end;
var wc: TWndClassEx = ( cbSize : SizeOf(TWndClassEx); Style : CS_HREDRAW or CS_VREDRAW; lpfnWndProc : @WndProc; cbClsExtra : 0; cbWndExtra : 0; hbrBackground : COLOR_APPWORKSPACE; lpszMenuName : nil; lpszClassName : ClassName; hIconSm : 0; ); msg: TMSG; done: Boolean = false;
begin wc.hInstance := hInstance; wc.hIcon := LoadIcon(0,IDI_APPLICATION); wc.hCursor := LoadCursor(0,IDC_ARROW); RegisterClassEx(wc); CreateWindowEx(0,ClassName,AppName,WS_CAPTION or WS_VISIBLE or WS_SYSMENU or WS_MINIMIZEBOX or WS_MAXIMIZEBOX or WS_SIZEBOX,Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT),WindowWidth,WindowHeight,0,0,hInstance,nil); while not done do begin if (PeekMessage(msg,0,0,0,PM_REMOVE)) then begin if msg.message=WM_QUIT then begin done:=true; end else begin TranslateMessage(msg); DispatchMessage(msg); end; end; //Keys Here! if Go[VK_ESCAPE] then done:=true;
if Go[VK_UP] then Rotate:=Rotate+3;
if Go[VK_DOWN] then Rotate:=Rotate-3; if Go[VK_LEFT] then MoveLR:=MoveLR+0.03;
if Go[VK_RIGHT] then MoveLR:=MoveLR-0.03;
DrawScene; SwapBuffers(h_DC); end; end. |