Home > C, My Tools, OpenGL, Programming > Is there simple way to create polygon stipple pattern?

Is there simple way to create polygon stipple pattern?

If you ever work With OpenGL you agree with me that this Library are wonderful, if you don’t know what is OpenGL I offer you to read Article form Wikipedia website

an Introduce of OpenGL library from Wikipedia:

OpenGL (Open Graphics Library) is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL was developed by Silicon Graphics Inc. (SGI) in 1992[2] and is widely used in CAD, virtual reality, scientific visualization, information visualization, and flight simulation. It is also used in video games, where it competes with Direct3D on Microsoft Windows platforms (see OpenGL vs. Direct3D). OpenGL is managed by a non-profit technology consortium, the Khronos Group.

I have a Computer Graphic course this term, it’s about 5 or 6 sessions that we pass the term, and about 2 sessions that we start programming part,  for me it’s really interesting part. yesterday our professor talked about creating stipple pattern for polygon object the approach we must use is preparing checkered paper that have 32*32 cell and draw something on it, OK after that we must convert it to array of 32*32 GLubyte (unsigned byte). each block represent a bit, so after that black blocks are represent ’1′ and white block represent ’0′, and the result are something like this:

example from  OpenGL SuperBible Fourth Edition Book

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
}

so you see the converting part are really hard work and I don’t find easy way to do this work, so I decide to write a program to make this process easier ;)

for this purpose you must create a monochrome bitmap( I do this with visual studio) and then use my program to create array and then copy it to your project for example here is monochrome bitmap I created with VS 2008

and properties must set for monochrome bitmap and with this command (-i for inverting bit):

makepattern.exe bitmap.bmp -i

this bring you the bellow output

// --------------------------------
GLubyte pattern[] = {
 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00,
 0x00, 0x42, 0x00, 0x00,
 0x00, 0x72, 0x08, 0x00,
 0x00, 0x1A, 0x18, 0x00,
 0x00, 0x07, 0xF0, 0x00,
 0x00, 0x03, 0x00, 0x00,
 0x00, 0x02, 0x00, 0x00,
 0x00, 0x03, 0xC0, 0x00,
 0x00, 0x0C, 0x60, 0x00,
 0x00, 0x30, 0x20, 0x00,
 0x00, 0x20, 0x60, 0x00,
 0x00, 0x60, 0xC0, 0x00,
 0x00, 0x40, 0x40, 0x00,
 0x00, 0x40, 0x40, 0x00,
 0x00, 0x40, 0x40, 0x00,
 0x00, 0x47, 0x40, 0x00,
 0x00, 0x40, 0x80, 0x00,
 0x00, 0x60, 0x80, 0x00,
 0x00, 0x3B, 0x80, 0x00,
 0x00, 0x0E, 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, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00
};
// --------------------------------

you can see entire work shown below and download source of this project at end of post, also to compile and run project you need GLUT library.

you can download the tools + source code from here I write it with C without any API, so with little change it can port to other OS

makepattern Download Lin

Dowload Project use  stipple pattern

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.