How does this line stipple stuff work?!!!

this code is from the OpenGL SuperBible and i was wondering what the hell this line stipple code like “0x00” means and how it works… thanx,

// PStipple.c
// OpenGL SuperBible, Chapter 4
// Demonstrates OpenGL Polygon Stippling
// Program by Richard S. Wright Jr.

#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#include <math.h>

// Define a constant for the value of PI
#define GL_PI 3.1415f

// Rotation amounts
static GLfloat xRot = 0.0f;
static GLfloat yRot = 0.0f;

// Bitmap of camp fire
GLubyte fire[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xc0,
0x00, 0x00, 0x01, 0xf0,
0x00, 0x00, 0x07, 0xf0,
0x0f, 0x00, 0x1f, 0xe0,
0x1f, 0x80, 0x1f, 0xc0,
0x0f, 0xc0, 0x3f, 0x80,
0x07, 0xe0, 0x7e, 0x00,
0x03, 0xf0, 0xff, 0x80,
0x03, 0xf5, 0xff, 0xe0,
0x07, 0xfd, 0xff, 0xf8,
0x1f, 0xfc, 0xff, 0xe8,
0xff, 0xe3, 0xbf, 0x70,
0xde, 0x80, 0xb7, 0x00,
0x71, 0x10, 0x4a, 0x80,
0x03, 0x10, 0x4e, 0x40,
0x02, 0x88, 0x8c, 0x20,
0x05, 0x05, 0x04, 0x40,
0x02, 0x82, 0x14, 0x40,
0x02, 0x40, 0x10, 0x80,
0x02, 0x64, 0x1a, 0x80,
0x00, 0x92, 0x29, 0x00,
0x00, 0xb0, 0x48, 0x00,
0x00, 0xc8, 0x90, 0x00,
0x00, 0x85, 0x10, 0x00,
0x00, 0x03, 0x00, 0x00,
0x00, 0x00, 0x10, 0x00 };

// Called to draw scene
void RenderScene(void)
// Clear the window

// Save matrix state and do the rotation
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);

// Begin the stop sign shape,
// use a standard polygon for simplicity
	glVertex2f(-20.0f, 50.0f);
	glVertex2f(20.0f, 50.0f);
	glVertex2f(50.0f, 20.0f);
	glVertex2f(50.0f, -20.0f);
	glVertex2f(20.0f, -50.0f);
	glVertex2f(-20.0f, -50.0f);
	glVertex2f(-50.0f, -20.0f);
	glVertex2f(-50.0f, 20.0f);

// Restore transformations

// Flush drawing commands

// This function does any needed initialization on the rendering
// context.
void SetupRC()
// Black background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );

// Set drawing color to red
glColor3f(1.0f, 0.0f, 0.0f);

// Enable polygon stippling

// Specify a specific stipple pattern

void SpecialKeys(int key, int x, int y)
if(key == GLUT_KEY_UP)
xRot-= 5.0f;

if(key == GLUT_KEY_DOWN)
	xRot += 5.0f;

if(key == GLUT_KEY_LEFT)
	yRot -= 5.0f;

if(key == GLUT_KEY_RIGHT)
	yRot += 5.0f;

if(key &gt; 356.0f)
	xRot = 0.0f;

if(key &lt; -1.0f)
	xRot = 355.0f;

if(key &gt; 356.0f)
	yRot = 0.0f;

if(key &lt; -1.0f)
	yRot = 355.0f;

// Refresh the Window

void ChangeSize(int w, int h)
GLfloat nRange = 100.0f;

// Prevent a divide by zero
if(h == 0)
	h = 1;

// Set Viewport to window dimensions
glViewport(0, 0, w, h);

// Reset projection matrix stack

// Establish clipping volume (left, right, bottom, top, near, far)
if (w &lt;= h) 
	glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
	glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);

// Reset Model view matrix stack

int main(int argc, char* argv[])
glutInit(&argc, argv);
glutCreateWindow(“Polygon Stippling”);

return 0;

Actually there is no line stipple in the program. It’s polygon stipple.
Fairly easy: OpenGL supports a 32x32 bit stipple pattern which is window relative and can be used to cull fragments. If polygon stipple is enabled, pixels are only set if the bit in the pattern is 1. This can be used to generate simple (ugly) transparency effects without the need for depth sorting the transparent polygons.
Or it can be used to fade in or out drawings by changing the stipple pattern in some orderer dither technique.

Line stipple is also available with a 16 bit 1D pattern.

Try the program you provided and you’ll see the polygon stipple drawing some pattern with a single primitive.

Originally posted by Y-T:
this code is from the OpenGL SuperBible and i was wondering what the hell this line stipple code like “0x00” means and how it works… thanx,

I think this is what it is… 0x?? represents a number in hex… a 16 bit number… (1 byte = 8 bits)

you need to convert each of the ?? into binary. So for example if you have 0x54 it would be this in binary:


//add the zeroes to turn it into a 16 bit


so your pattern comes out to be:

0x54 =


so by having a lot of these you can make a pattern…

by the way the letters are
(no g because it’s base 16, thus next would come 0, then 1…)

Hope this helps

Errr…, ngill, 0x?? is 8bit !!! the first ? is the first 4 bits !!! and the second ? is the last 4 bits. 16 bits would be 0x???.

heh heh, should’ve noticed that…

yeah the highest ? = f(15) thus:

1111… 4 bit gives (2^4)16 possibilites, not 16 1s and 0s, whoopsa.

I guess I wasn’t thinking…