Made wxGTK dataobj.cpp compile; removed flashing from wxGLCanvas samples;

some doc bug fixes


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1465 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
1999-01-24 23:56:51 +00:00
parent ba681060f3
commit 06ad863606
25 changed files with 428 additions and 213 deletions

View File

@@ -0,0 +1,161 @@
/////////////////////////////////////////////////////////////////////////////
// Name: glcanvas.cpp
// Purpose: wxGLCanvas, for using OpenGL with wxWindows 2.0 for Motif.
// Uses the GLX extension.
// Author: Julian Smart and Wolfram Gloger
// Modified by:
// Created: 1995, 1999
// RCS-ID: $Id$
// Copyright: (c) Julian Smart, Wolfram Gloger
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "glcanvas.h"
#endif
#include "glcanvas.h"
#include "wx/utils.h"
#include "wx/app.h"
#include <Xm/Xm.h>
#include "wx/motif/private.h"
#ifdef OLD_MESA
// workaround for bug in Mesa's glx.c
static int bitcount( unsigned long n )
{
int bits;
for (bits=0; n>0;) {
if(n & 1) bits++;
n = n >> 1;
}
return bits;
}
#endif
/*
* GLCanvas implementation
*/
IMPLEMENT_CLASS(wxGLCanvas, wxScrolledWindow)
wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos,
const wxSize& size, long style,
const wxString& name, int *attrib_list, const wxPalette& palette):
wxScrolledWindow(parent, id, pos, size, style, name)
{
XVisualInfo *vi, vi_templ;
XWindowAttributes xwa;
int val, n;
Display* display = (Display*) GetXDisplay();
glx_cx = 0;
// Check for the presence of the GLX extension
if(!glXQueryExtension(display, NULL, NULL)) {
wxDebugMsg("wxGLCanvas: GLX extension is missing\n");
return;
}
if(attrib_list) {
// Get an appropriate visual
vi = glXChooseVisual(display, DefaultScreen(display), attrib_list);
if(!vi) return;
// Here we should make sure that vi is the same visual as the
// one used by the xwindow drawable in wxCanvas. However,
// there is currently no mechanism for this in wx_canvs.cc.
} else {
// By default, we use the visual of xwindow
XGetWindowAttributes(display, (Window) GetXWindow(), &xwa);
vi_templ.visualid = XVisualIDFromVisual(xwa.visual);
vi = XGetVisualInfo(display, VisualIDMask, &vi_templ, &n);
if(!vi) return;
glXGetConfig(display, vi, GLX_USE_GL, &val);
if(!val) return;
// Basically, this is it. It should be possible to use vi
// in glXCreateContext() below. But this fails with Mesa.
// I notified the Mesa author about it; there may be a fix.
#ifdef OLD_MESA
// Construct an attribute list matching the visual
int a_list[32];
n = 0;
if(vi->c_class==TrueColor || vi->c_class==DirectColor) { // RGBA visual
a_list[n++] = GLX_RGBA;
a_list[n++] = GLX_RED_SIZE;
a_list[n++] = bitcount(vi->red_mask);
a_list[n++] = GLX_GREEN_SIZE;
a_list[n++] = bitcount(vi->green_mask);
a_list[n++] = GLX_BLUE_SIZE;
a_list[n++] = bitcount(vi->blue_mask);
glXGetConfig(display, vi, GLX_ALPHA_SIZE, &val);
a_list[n++] = GLX_ALPHA_SIZE;
a_list[n++] = val;
} else { // Color index visual
glXGetConfig(display, vi, GLX_BUFFER_SIZE, &val);
a_list[n++] = GLX_BUFFER_SIZE;
a_list[n++] = val;
}
a_list[n] = None;
XFree(vi);
vi = glXChooseVisual(display, DefaultScreen(display), a_list);
if(!vi) return;
#endif /* OLD_MESA */
}
// Create the GLX context and make it current
glx_cx = glXCreateContext(display, vi, 0, GL_TRUE);
#ifndef OLD_MESA
XFree(vi);
#endif
SetCurrent();
}
wxGLCanvas::~wxGLCanvas(void)
{
Display* display = (Display*) GetXDisplay();
if(glx_cx) glXDestroyContext(display, glx_cx);
}
void wxGLCanvas::SwapBuffers()
{
Display* display = (Display*) GetXDisplay();
if(glx_cx) glXSwapBuffers(display, (Window) GetXWindow());
}
void wxGLCanvas::SetCurrent()
{
Display* display = (Display*) GetXDisplay();
if(glx_cx) glXMakeCurrent(display, (Window) GetXWindow(), glx_cx);
}
void wxGLCanvas::SetColour(const char *col)
{
wxColour *the_colour = wxTheColourDatabase->FindColour(col);
if(the_colour) {
GLboolean b;
glGetBooleanv(GL_RGBA_MODE, &b);
if(b) {
glColor3ub(the_colour->Red(),
the_colour->Green(),
the_colour->Blue());
} else {
GLint pix = (GLint)the_colour->m_pixel;
if(pix == -1) {
XColor exact_def;
exact_def.red = (unsigned short)the_colour->Red() << 8;
exact_def.green = (unsigned short)the_colour->Green() << 8;
exact_def.blue = (unsigned short)the_colour->Blue() << 8;
exact_def.flags = DoRed | DoGreen | DoBlue;
if(!XAllocColor((Display*) GetXDisplay(), (Colormap) wxTheApp->GetMainColormap(GetXDisplay()), &exact_def)) {
wxDebugMsg("wxGLCanvas: cannot allocate color\n");
return;
}
pix = the_colour->m_pixel = exact_def.pixel;
}
glIndexi(pix);
}
}
}

View File

@@ -0,0 +1,44 @@
/////////////////////////////////////////////////////////////////////////////
// Name: glcanvas.h
// Purpose: wxGLCanvas, for using OpenGL with wxWindows 2.0 for Motif.
// Uses the GLX extension.
// Author: Julian Smart and Wolfram Gloger
// Modified by:
// Created: 1995, 1999
// RCS-ID: $Id$
// Copyright: (c) Julian Smart, Wolfram Gloger
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma interface "glcanvas.h"
#endif
#ifndef _WX_GLCANVAS_H_
#define _WX_GLCANVAS_H_
#include "wx/setup.h"
#include "wx/gdicmn.h"
#include "wx/palette.h"
#include "wx/scrolwin.h"
#include <GL/glx.h>
class wxGLCanvas: public wxScrolledWindow
{
DECLARE_CLASS(wxGLCanvas)
public:
GLXContext glx_cx;
wxGLCanvas(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0,
const wxString& name = "GLCanvas", int *attribList = 0, const wxPalette& palette = wxNullPalette);
~wxGLCanvas(void);
void SetCurrent();
void SwapBuffers();
void SetColour(const char *col);
};
#endif
// _WX_GLCANVAS_H_

View File

@@ -0,0 +1,20 @@
#
# File: makefile.unx
# Author: Julian Smart
# Created: 1998
# Updated:
# Copyright: (c) 1998 Julia`n Smart
#
# "%W% %G%"
#
# Makefile for wxGLCanvas (Unix)
LIBTARGET=$(WXWIN)/lib/libglcanvas
OPENGLHOME=/home/jacs/mesa/Mesa-2.3
EXTRACPPFLAGS=-I$(OPENGLHOME)/include
OBJECTS=glcanvas.o
include ../../../src/makelib.env

View File

@@ -0,0 +1,52 @@
GLCanvas class for wxWindows 1.66 using the GLX protocol extension
==================================================================
I have just uploaded a file 'wx166glx.tar.gz' to the wxWindows
incoming directory. It contains an implementation of a GLCanvas class
(interfacing an ordinary wxCanvas with OpenGL calls) for X11 (I tested
with Motif, maybe it works with XView as well). I tried to imitate
what Julian did in 'wxmesa1.zip' for MS Windows in conjunction with
the Mesa library.
Of the several possibilities to use OpenGL under X11, I chose the GLX
server extension, because it is the most efficient method on machines
with graphics hardware support (I expect wxWindows/OpenGL applications
to _fly_ on my Indy :-). However, you don't need a 'real' OpenGL
implementation to use GLCanvas -- the free Mesa library has a
simulated GLX interface built-in. Just link in libMesaGLU and
libMesaGL along with libwx_motif and everything should work fine.
Installation:
Untar wx166glx.tar.gz from your main wxWindows directory (i.e. where
the `include' and `src' subdirectories are). Then apply the small
patch file which has appeared in the `glx' subdirectory:
% patch -p0 < glx/wx166-glx.diff
Recompile the wx_motif library in the standard way. The inclusion of
the GLCanvas class in libwx_motif is protected with a new 'USE_GLX'
flag in wx_setup.h, so it could maybe be included in a future
wxWindows release (with USE_GLX turned off by default).
Two new samples (bounce and prim) are included. I adapted them from
wxmesa1.zip -- they should compile under both MS Windows (with wxMesa)
and X11. The makefile.unx's are set up for the Mesa libraries; if you
have original libGLU/libGL's just change the GLLIBS = ... line.
Problems:
One more or less serious problem remains: the visual generated by the
GLCanvas class must match the visual of wxCanvas.xwindow (which
currently is always the screen's default visual). The end result is
that you will get a nice RGB mode for OpenGL only if your display's
default visual is TrueColor or DirectColor (the XFree86 S3 servers for
PCs with the '-bpp 16/32' option are examples). I'm contemplating a
solution where the wxCanvas drawingarea widget is destroyed and then
re-created from within the GLCanvas constructor. I would welcome
suggestions on this and discussions of the GLCanvas 'API'.
Regards,
Wolfram Gloger.
(Gloger@lrz.uni-muenchen.de)

View File

@@ -387,7 +387,7 @@ void TestGLCanvas::OnChar(wxKeyEvent& event)
break;
}
Refresh();
Refresh(FALSE);
}
void TestGLCanvas::OnMouseEvent(wxMouseEvent& event)
@@ -402,7 +402,7 @@ void TestGLCanvas::OnMouseEvent(wxMouseEvent& event)
} else {
yrot += (event.GetX() - last_x)*1.0;
xrot += (event.GetY() - last_y)*1.0;
Refresh();
Refresh(FALSE);
}
last_x = event.GetX();
last_y = event.GetY();

View File

@@ -106,7 +106,9 @@ void TestGLCanvas::OnPaint( wxPaintEvent& event )
/* must always be here */
wxPaintDC dc(this);
#ifndef __WXMOTIF__
if (!GetContext()) return;
#endif
SetCurrent();
@@ -149,7 +151,9 @@ void TestGLCanvas::OnSize(wxSizeEvent& event)
int width, height;
GetClientSize(& width, & height);
#ifndef __WXMOTIF__
if (GetContext())
#endif
{
SetCurrent();
glViewport(0, 0, width, height);
@@ -197,7 +201,7 @@ void TestGLCanvas::OnMouse( wxMouseEvent& event )
add_quats( spin_quat, info.quat, info.quat );
/* orientation has changed, redraw mesh */
Refresh();
Refresh(FALSE);
}
info.beginx = event.GetX();