Cita:
Empezado por mirkogonzales
Si ya las he leido y si alguien me podria orientar se los agradeceria. He leido varios tutoriales y libritos (ademas de foros en otros idiomas) pero no le encuentro solución. Gracias y saludos.
|
En fin, mirko, tendre que echante una mano
En un nuevo formulario añade el uses "OpenGL" y a partir del codigo que muestro tendras que trabajar un poco, pero la base ya te la doy echa. Basicamente lo que hace es iniciar el contexto opengl, cerrando y diseñar el "cubo" de trabajo, espero que te sirva.
Código Delphi
[-]
uses Form, OpenGl, etc.
procedure TfrmOpenGl.glInicia;
var
PixelFormat : Integer;
pfd : PIXELFORMATDESCRIPTOR;
begin
h_DC := GetDC(frmOpenGl.Handle);
if h_DC = NULL then begin
Application.MessageBox('No se ha asignado contexto de formulario',
'frmOpenGl', MB_OK or MB_ICONERROR);
Exit;
end;
ZeroMemory(@pfd, SizeOf(pfd));
pfd.nSize := SizeOf(PIXELFORMATDESCRIPTOR);
pfd.nVersion := 1;
pfd.dwFlags := PFD_DRAW_TO_WINDOW
or PFD_SUPPORT_OPENGL
or PFD_DOUBLEBUFFER;
pfd.iPixelType := PFD_TYPE_RGBA;
pfd.cColorBits := 16;
pfd.cDepthBits := 16;
PixelFormat := ChoosePixelFormat(h_DC, @pfd);
if (PixelFormat = 0) then begin
glAcaba();
MessageBox(0, 'No puedo cambiar el descriptor de pixeles', 'Error',
MB_OK or MB_ICONERROR);
Exit;
end;
if (not SetPixelFormat(h_DC, PixelFormat, @pfd)) then begin
glAcaba();
MessageBox(0, 'No puedo definir un formato de pixeles', 'Error',
MB_OK or MB_ICONERROR);
Exit;
end;
h_RC := wglCreateContext(h_DC);
if (h_RC = 0) then begin
glAcaba();
MessageBox(0, 'No puedo crear el contexto OpenGL sobre el formulario',
'Error', MB_OK or MB_ICONERROR);
Exit;
end;
if (not wglMakeCurrent(h_DC, h_RC)) then begin
glAcaba();
MessageBox(0, 'No puedo activar el contexto de generación OpenGl', 'Error',
MB_OK or MB_ICONERROR);
Exit;
end;
SetForegroundWindow(frmOpenGl.Handle);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glIniciaLuz();
end;
procedure TfrmOpenGl.glAcaba();
begin
if (not wglMakeCurrent(h_DC, 0)) then begin
MessageBox(0, 'Devolver recursos OpenGl', 'Error',
MB_OK or MB_ICONERROR);
h_DC := null;
end;
if (not wglDeleteContext(h_RC)) then begin
MessageBox(0, 'Borrar contexto OpenGl', 'Error',
MB_OK or MB_ICONERROR);
h_RC := 0;
end;
end;
procedure TfrmOpenGl.glAjustaVentana();
var
rojo, verde, azul: glDouble;
w, h, i, c: Integer;
newExtX, newExtY, newExtZ: glDouble;
begin
Val(EditAreaX.Text, i, c);
if c = 0 then extX := i; Val(EditAreaY.Text, i, c);
if c = 0 then extY := i; Val(EditAreaZ.Text, i, c);
if c = 0 then extZ := i; w := frmOpenGl.Width; h := frmOpenGl.Height - 30; glViewport(0, 0, w, h); newExtX := extX; newExtY := extY; newExtZ := extZ;
if SpinZoom.Position > 99 then SpinZoom.Position := 99;
newExtX := newExtX - ((SpinZoom.Position * newExtX) / 100);
newExtY := newExtY - ((SpinZoom.Position * newExtY) / 100);
newExtZ := newExtZ - ((SpinZoom.Position * newExtZ) / 100);
glMatrixMode(GL_PROJECTION); glLoadIdentity(); if w <= h then begin
glOrtho(-newExtX, newExtX,
-newExtY * h / w, newExtY * h / w,
-newExtZ * 100, newExtZ * 100);
end else begin
glOrtho(-newExtX * w / h, newExtX * w / h,
-newExtY, newExtY,
-newExtZ * 100, newExtZ * 100);
end;
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); rojo := 0; verde := 0; azul := 0;
Val(SimCfg.SpinRojo.Text, i, c);
if c = 0 then rojo := i / 100;
Val(SimCfg.SpinVerde.Text, i, c);
if c = 0 then verde := i / 100;
Val(SimCfg.SpinAzul.Text, i, c);
if c = 0 then azul := i / 100;
glClearColor(rojo, verde, azul, 1.0);
glClear(GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT);
end;