Re: OpenGL Panes
davef@xanalys.com writes:
>
> 1. changed the first form to (in-package "OPENGL")
I have worked on the example and changed it to:
(in-package :cl-user)
(use-package :opengl)
(capi:define-interface opengl-interface ()
()
(:panes
(og-pane
capi:opengl-pane
:configuration (list :rgba t)
:pane-can-scroll t
:display-callback #'display-fun
:resize-callback #'resize-fun
:external-min-height 500
:external-min-width 500
:horizontal-scroll t
:vertical-scroll t))
(:layouts
(column-layout-1
capi:column-layout
'(og-pane)))
(:default-initargs
:best-height 564
:best-width 516
:layout 'column-layout-1
:title "OpenGL Tests"))
(defun resize-fun (canvas x y width height)
(gl-viewport x y width height)
(gl-matrix-mode *gl-projection*)
(gl-load-identity)
(gl-frustum -1.0 1.0 -1.0 1.0 1.5 20.0)
(gl-matrix-mode *gl-modelview*)
(display-fun canvas))
(defmethod initialize-instance :after ((self opengl-interface) &rest ignore &key &allow-other-keys)
(gl-clear-color 0.0 0.0 0.0 0.0)
(gl-shade-model *gl-flat*))
(defun display-fun (canvas &rest r)
(declare (ignore r))
(rendering-on (canvas)
(gl-clear *gl-color-buffer-bit*)
(gl-color3-f 1.0 0.0 0.0)
(gl-matrix-mode *gl-modelview*)
(gl-load-identity)
(glu-look-at 0.5 0.0 -0.8 0.0 0.0 0.0 0.0 1.0 0.0)
(gl-begin *gl-polygon*)
(gl-vertex3-f -0.25 -0.25 0.0)
(gl-vertex3-f -0.25 0.25 0.0)
(gl-vertex3-f 0.25 0.25 0.0)
(gl-vertex3-f 0.25 -0.25 0.0)
(gl-end)
(gl-flush)))
;; (fli:register-module "/usr/lib/libglut.so")
;; (fli:define-foreign-function (glut-wire-cube "glutWireCube")
;; ((size (:double-float)))
;; :result-type (:void)
;; :language :ansi-c)
(defun run-it ()
(setf *interface* (capi:display (make-instance 'opengl-interface))))
(run-it)
this code works as intended.
>
> 2. replaced #'resize-fun with #'resize-lesson
>
> 3. built and used a combined *.so containing libglut.so similar to
> that described in opengl/loader.lisp, by
> ld -shared -o glfd.so -L/usr/X11R6/lib -lglut -lGLU -lGL
Well glut is not part of it here. In my loader.lisp I just find
;; $ ld -shared -o gl.so -L/usr/X11R6/lib -lGLU -lGL
But I guess this is just minor problem. I will change that here.
>
> After these changes your interface displays by (run-it) and is
> horizontally scrollable, although I get many messages
>
> GL User Error: calling glClearColor without a current context
> GL User Error: calling glShadeModel without a current context
> GL User Error: calling glViewport without a current context
> etc
Well my code is oviously wrong (I just haven't seen it) It's a
rendering-on missing in draw-fun.
I even think that I won't get that code running in a way like that
because glut has to be initalized to (which I did not), so it won't
work anyway.
I'm lacking probably too much to understand how things work. E.g do I
not understand why I have to keep the cooridnates within -1.0 -
1.0. The conversion with gl-scalef, glu-look-at, gl-frustum etc should
make it possible to use other numbers too. But I do not understand,
how C and Common Lisp differ here.
Anyway if someone will give me a hand getting this running with
LispWorks OpenGL would be very nice.
Here's the c-code (part of the sources from the redbook, cube.c
/*
* Copyright (c) 1993-1999, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
*/
/*
* cube.c
* This program demonstrates a single modeling transformation,
* glScalef() and a single viewing transformation, gluLookAt().
* A wireframe cube is rendered.
*/
#include <GL/glut.h>
#include <stdlib.h>
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity (); /* clear the matrix */
/* viewing transformation */
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef (1.0, 2.0, 1.0); /* modeling transformation */
glutWireCube (1.0);
glFlush ();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
This is a cube which is seen from a different angle and scaled
differently in y direction it looks now like a cuboid. Well what I
just want to get running is the display function... But I don't think
that the glut-wire-cube function will work without preparation...
Another question I have is with the example provided with the OpenGL
stuff. Can you steer the interface of it with the keyboard on Linux?
Regards
Friedrich