summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Fl_Gl_Overlay.cxx64
-rw-r--r--src/Fl_Gl_Window.cxx69
-rw-r--r--src/gl_draw.cxx19
3 files changed, 91 insertions, 61 deletions
diff --git a/src/Fl_Gl_Overlay.cxx b/src/Fl_Gl_Overlay.cxx
index d9416e9e4..f47e47f0f 100644
--- a/src/Fl_Gl_Overlay.cxx
+++ b/src/Fl_Gl_Overlay.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Gl_Overlay.cxx,v 1.5.2.3 2000/03/18 10:04:17 bill Exp $"
+// "$Id: Fl_Gl_Overlay.cxx,v 1.5.2.4 2000/03/24 08:42:02 bill Exp $"
//
// OpenGL overlay code for the Fast Light Tool Kit (FLTK).
//
@@ -103,11 +103,15 @@ int Fl_Gl_Window::can_do_overlay() {
#else // WIN32:
+static int no_overlay_hardware = 0;
int Fl_Gl_Window::can_do_overlay() {
+ if (no_overlay_hardware) return 0;
Fl_Gl_Choice* choice = Fl_Gl_Choice::find(0,0);
return (choice && (choice->pfd.bReserved & 15));
}
+int fl_overlay_depth = 0;
+
#endif
#else
@@ -116,28 +120,50 @@ int Fl_Gl_Window::can_do_overlay() {return 0;}
#endif
+#include <stdio.h>
+
void Fl_Gl_Window::make_overlay() {
if (!overlay) {
#if HAVE_GL_OVERLAY
#ifdef WIN32
- HDC hdc = fl_private_dc(this, mode_,&g);
- GLXContext context = wglCreateLayerContext(hdc, 1);
- if (context) {
- if (fl_first_context) wglShareLists(fl_first_context, context);
- else fl_first_context = context;
- overlay = context;
- // copy all colors except #0 into the overlay palette:
- COLORREF pcr[256];
- for (int i = 0; i < 256; i++) {
- uchar r,g,b; Fl::get_color((Fl_Color)i,r,g,b);
- pcr[i] = RGB(r,g,b);
+ if (!no_overlay_hardware) {
+ HDC hdc = fl_private_dc(this, mode_,&g);
+ GLXContext context = wglCreateLayerContext(hdc, 1);
+ if (!context) { // no overlay hardware
+ no_overlay_hardware = 1;
+ printf("No overlay detected\n");
+ } else {
+ if (fl_first_context) wglShareLists(fl_first_context, context);
+ else fl_first_context = context;
+ overlay = context;
+ LAYERPLANEDESCRIPTOR pfd;
+ wglDescribeLayerPlane(hdc, g->pixelformat, 1, sizeof(pfd), &pfd);
+ if (!pfd.iPixelType) {
+ printf("Color Overlay found\n");
+ } else {
+ printf("Overlay of depth %d found\n", pfd.cColorBits);
+ fl_overlay_depth = pfd.cColorBits; // used by gl_color()
+ if (fl_overlay_depth > 8) fl_overlay_depth = 8;
+ COLORREF palette[256];
+ // copy all colors except #0 into the overlay palette:
+ for (int i = 0; i < 256; i++) {
+ uchar r,g,b; Fl::get_color((Fl_Color)i,r,g,b);
+ palette[i] = RGB(r,g,b);
+ }
+ // always provide black & white in the last 2 pixels:
+ if (fl_overlay_depth < 8) {
+ palette[(1<<fl_overlay_depth)-2] = RGB(0,0,0);
+ palette[(1<<fl_overlay_depth)-1] = RGB(255,255,255);
+ }
+ // and use it:
+ wglSetLayerPaletteEntries(hdc, 1, 1, 255, palette+1);
+ wglRealizeLayerPalette(hdc, 1, TRUE);
+ }
+ valid(0);
+ return;
}
- wglSetLayerPaletteEntries(hdc, 1, 1, 255, pcr+1);
- wglRealizeLayerPalette(hdc, 1, TRUE);
- valid(0);
- return;
}
-#else // glX version:
+#else
if (can_do_overlay()) {
_Fl_Gl_Overlay* o = new _Fl_Gl_Overlay(0,0,w(),h());
overlay = o;
@@ -168,6 +194,8 @@ void Fl_Gl_Window::make_overlay_current() {
if (overlay != this) {
#ifdef WIN32
fl_set_gl_context(this, (GLXContext)overlay);
+ if (fl_overlay_depth)
+ wglRealizeLayerPalette(fl_private_dc(this, mode_,&g), 1, TRUE);
#else
((Fl_Gl_Window*)overlay)->make_current();
#endif
@@ -189,5 +217,5 @@ void Fl_Gl_Window::hide_overlay() {
#endif
//
-// End of "$Id: Fl_Gl_Overlay.cxx,v 1.5.2.3 2000/03/18 10:04:17 bill Exp $".
+// End of "$Id: Fl_Gl_Overlay.cxx,v 1.5.2.4 2000/03/24 08:42:02 bill Exp $".
//
diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx
index 83242e957..601f73404 100644
--- a/src/Fl_Gl_Window.cxx
+++ b/src/Fl_Gl_Window.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Gl_Window.cxx,v 1.12.2.8 2000/03/18 10:04:18 bill Exp $"
+// "$Id: Fl_Gl_Window.cxx,v 1.12.2.9 2000/03/24 08:42:02 bill Exp $"
//
// OpenGL window code for the Fast Light Tool Kit (FLTK).
//
@@ -59,14 +59,6 @@
#define SWAP_TYPE SWAP
#endif
-//
-// Windows may need a different color palette...
-//
-
-#if defined(WIN32) && HAVE_GL
-extern HPALETTE fl_gl_palette;
-#endif
-
////////////////////////////////////////////////////////////////
int Fl_Gl_Window::can_do(int a, const int *b) {
@@ -159,41 +151,57 @@ void Fl_Gl_Window::swap_buffers() {
#endif
}
-#if HAVE_GL_OVERLAY
-#ifdef WIN32
+#if defined(_WIN32) && HAVE_GL_OVERLAY
uchar fl_overlay; // changes how fl_color() works
#endif
-#endif
void Fl_Gl_Window::flush() {
- make_current();
+ uchar save_valid = valid_;
#if defined(_WIN32) && HAVE_GL_OVERLAY
- uchar save_valid = valid_;
- if (overlay && overlay!= this && damage() == FL_DAMAGE_OVERLAY) goto DRAW_OVERLAY_ONLY;
+ if (overlay && overlay != this &&
+ ((damage()&(FL_DAMAGE_OVERLAY|FL_DAMAGE_ALL|FL_DAMAGE_EXPOSE))
+ || !save_valid)) {
+ // Draw into hardware overlay planes
+ if (!g->d) SetCursor(0); // SGI 320 messes up overlay over singlebuffer
+ fl_set_gl_context(this, (GLXContext)overlay);
+ glDisable(GL_SCISSOR_TEST);
+ glClear(GL_COLOR_BUFFER_BIT);
+ fl_overlay = 1;
+ draw_overlay();
+ fl_overlay = 0;
+ valid(save_valid);
+ if (damage() == FL_DAMAGE_OVERLAY) {
+ wglSwapLayerBuffers(Fl_X::i(this)->private_dc,WGL_SWAP_OVERLAY1);
+ if (!g->d) SetCursor(Fl_X::i(this)->cursor);
+ return;
+ }
+ if (!g->d) SetCursor(Fl_X::i(this)->cursor);
+ }
#endif
+ make_current();
+
if (g->d) {
#if SWAP_TYPE == NODAMAGE
// don't draw if only overlay damage or expose events:
- if ((damage()&~(FL_DAMAGE_OVERLAY|FL_DAMAGE_EXPOSE)) || !valid()) draw();
+ if ((damage()&~(FL_DAMAGE_OVERLAY|FL_DAMAGE_EXPOSE)) || !save_valid) draw();
swap_buffers();
#elif SWAP_TYPE == COPY
// don't draw if only the overlay is damaged:
- if (damage() != FL_DAMAGE_OVERLAY || !valid()) draw();
+ if (damage() != FL_DAMAGE_OVERLAY || !save_valid) draw();
swap_buffers();
#else // SWAP_TYPE == SWAP || SWAP_TYPE == UNDEFINED
if (overlay == this) { // Use CopyPixels to act like SWAP_TYPE == COPY
- uchar save_valid = valid_;
// don't draw if only the overlay is damaged:
- if (damage1_ || damage() != FL_DAMAGE_OVERLAY || !valid()) draw();
+ if (damage1_ || damage() != FL_DAMAGE_OVERLAY || !save_valid) draw();
// we use a seperate context for the copy because rasterpos must be 0
// and depth test needs to be off:
static GLXContext ortho_context = 0;
@@ -207,7 +215,6 @@ void Fl_Gl_Window::flush() {
#endif
fl_set_gl_context(this, ortho_context);
if (init || !save_valid || ortho_window != this) {
- ortho_window = this;
glDisable(GL_DEPTH_TEST);
glReadBuffer(GL_BACK);
glDrawBuffer(GL_FRONT);
@@ -215,6 +222,7 @@ void Fl_Gl_Window::flush() {
glViewport(0, 0, w(), h());
glOrtho(0, w(), 0, h(), -1, 1);
glRasterPos2i(0,0);
+ ortho_window = this;
}
glCopyPixels(0,0,w(),h(),GL_COLOR);
make_current(); // set current context back to draw overlay
@@ -251,25 +259,6 @@ void Fl_Gl_Window::flush() {
}
-#if HAVE_GL_OVERLAY
-#ifdef WIN32
- if (overlay && overlay != this) {
- DRAW_OVERLAY_ONLY:
- // Draw into hardware overlay planes
- if (!g->d) SetCursor(0); // SGI system messes up overlay over singlebuffer
- valid_ = save_valid;
- fl_set_gl_context(this, (GLXContext)overlay);
- glDisable(GL_SCISSOR_TEST);
- fl_overlay = 1;
- glClear(GL_COLOR_BUFFER_BIT);
- draw_overlay();
- wglSwapLayerBuffers(Fl_X::i(this)->private_dc,WGL_SWAP_OVERLAY1);
- fl_overlay = 0;
- if (!g->d) SetCursor(Fl_X::i(this)->cursor);
- }
-#endif
-#endif
-
valid(1);
}
@@ -318,5 +307,5 @@ void Fl_Gl_Window::draw_overlay() {}
#endif
//
-// End of "$Id: Fl_Gl_Window.cxx,v 1.12.2.8 2000/03/18 10:04:18 bill Exp $".
+// End of "$Id: Fl_Gl_Window.cxx,v 1.12.2.9 2000/03/24 08:42:02 bill Exp $".
//
diff --git a/src/gl_draw.cxx b/src/gl_draw.cxx
index c20b7b1a1..03b1cf924 100644
--- a/src/gl_draw.cxx
+++ b/src/gl_draw.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: gl_draw.cxx,v 1.7 1999/01/07 19:17:46 mike Exp $"
+// "$Id: gl_draw.cxx,v 1.7.2.1 2000/03/24 08:42:03 bill Exp $"
//
// OpenGL drawing support routines for the Fast Light Tool Kit (FLTK).
//
@@ -117,12 +117,25 @@ void gl_rect(int x, int y, int w, int h) {
#if HAVE_GL_OVERLAY
extern uchar fl_overlay;
+extern int fl_overlay_depth;
#endif
void gl_color(Fl_Color i) {
#if HAVE_GL_OVERLAY
#ifdef WIN32
- if (fl_overlay) {glIndexi(i ? i : FL_GRAY_RAMP); return;}
+ if (fl_overlay && fl_overlay_depth) {
+ if (fl_overlay_depth < 8) {
+ // only black & white produce the expected colors. This could
+ // be improved by fixing the colormap set in Fl_Gl_Overlay.cxx
+ int size = 1<<fl_overlay_depth;
+ if (!i) glIndexi(size-2);
+ else if (i >= size-2) glIndexi(size-1);
+ else glIndexi(i);
+ } else {
+ glIndexi(i ? i : FL_GRAY_RAMP);
+ }
+ return;
+ }
#else
if (fl_overlay) {glIndexi(int(fl_xpixel(i))); return;}
#endif
@@ -142,5 +155,5 @@ void gl_draw_image(const uchar* b, int x, int y, int w, int h, int d, int ld) {
#endif
//
-// End of "$Id: gl_draw.cxx,v 1.7 1999/01/07 19:17:46 mike Exp $".
+// End of "$Id: gl_draw.cxx,v 1.7.2.1 2000/03/24 08:42:03 bill Exp $".
//