Author Topic: [BMAX + OpenGL] Stipple polygons.  (Read 7287 times)

0 Members and 1 Guest are viewing this topic.

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
[BMAX + OpenGL] Stipple polygons.
« on: March 27, 2009 »
I've needed a way to draw stippled polygons. I'm not quite sure how to translate the example in my book into the Bmax equivalent.

Now in the example they specify a stipple pattern like this: (strait out of the Red Book p.58 in mine)

Code: [Select]
GLubyte halftone[] = {
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
        0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55};

How does this translate to Bmax? Do I need a 2 dimensional array or a single dimensional array? The book mentions that they can be 32x32 byte arrays. The syntax for the array is what throws me, no size value is given nor is there any dimensional value given.
« Last Edit: March 27, 2009 by Pixel_Outlaw »
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #1 on: March 27, 2009 »
The stipple-pattern is a 32x32 *bit*mask (there's no option about the size), so glPolygonStipple expects a pointer to 1024 bits (or 128 bytes or 32 dwords).
2d-arrays are laid out linearly in memory (it's a 1d-array and the compiler secretly computes the correct address for you), so it doesn't really matter how you declare your data - OpenGL just requires the address of the first value.
Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #2 on: March 27, 2009 »
You would use a 1 dimension byte array,so you could go something like

Local halftone:Byte[]=[Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85),Byte(170), Byte(170), Byte(170), Byte(170), Byte(85), Byte(85), Byte(85), Byte(85)]


I think that would do it, then you can pass the array to the required function, I have put what I think the values are for the hex OxAA and Ox55. I will be honest I havent tried the polygon stipple feature, so it might need some tweaking :)

For anyone who's wondering what were talking about you can check out the online Version 1 "red book" this is from chapter 2 about half way down the webpage :)

[Edit] Added a complete array for the halftone that works but I think there's likely an easier way  :D
« Last Edit: March 27, 2009 by TinDragon »

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #3 on: March 27, 2009 »
You could also do something like this to create the byte array:

Code: [Select]
Local halftone:Byte[128]

For Local i:Int = 0 To 127
ReadData halftone[i]
Next

DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #4 on: March 27, 2009 »
Ah there we go, new there would be an easier way :D and why the hell did i change the hex to decimal  ???
Probably shouldn't post when I just got up :D

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #5 on: March 27, 2009 »
Thanks for cleaning that up gents. ;)
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #6 on: March 27, 2009 »
I just thought I;d try it with one of the basic Nehe tutorials.

I must be doing something wrong here...

Code: [Select]
GLGraphics 640,480

glEnable(GL_POLYGON_STIPPLE)
glEnable GL_DEPTH_TEST 'Enables Depth Testing

glMatrixMode GL_PROJECTION 'Select The Projection Matrix
glLoadIdentity 'Reset The Projection Matrix

glFrustum -0.1, 0.1,-0.1, 0.1, 0.1, 100.0 'Setup The Projection Matrix Frustum

glMatrixMode GL_MODELVIEW 'Select The ModelView Matrix
glLoadIdentity 'Reset The ModelView Matrix

Local rtri:Float 'Angle For The Triangle ( New )
Local rquad:Float 'Angle For The Quad     ( New )


'stipple patern
Local HALFTONE:Byte[128]

For Local i:Int = 0 To 127
ReadData halftone[i]
Next

DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55
DefData $AA, $AA, $AA, $AA, $55, $55, $55, $55

glPolygonStipple(HALFTONE)

While Not KeyHit(KEY_ESCAPE)

glClear GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT 'Clear The Screen And The Depth Buffer

glLoadIdentity 'Reset The ModelView Matrix
glTranslatef -1.5,0.0,-6.0 'Move Left 1.5 Units And Into The Screen 6.0

glRotatef rtri,0.0,1.0,0.0 'Rotate The Triangle On The Y axis ( New )

glBegin GL_TRIANGLES 'Drawing Using Triangles
glColor3f 1.0, 0.0, 0.0 'Set The Color To Red
glVertex3f 0.0, 1.0, 0.0 'Top
glColor3f 0.0,1.0,0.0 'Set The Color To Green
glVertex3f -1.0,-1.0, 0.0 'Bottom Left
glColor3f 0.0,0.0,1.0 'Set The Color To Blue
glVertex3f 1.0,-1.0, 0.0 'Bottom Right

glEnd 'Finished Drawing The Triangle

glLoadIdentity() 'Reset The Current Modelview Matrix
glTranslatef 1.5,0.0,-6.0 'Move Right 1.5 Units And Into The Screen 6.0
glRotatef rquad,1.0,0.0,0.0 'Rotate The Quad On The X axis ( New )

glColor3f 0.5,0.5,1.0 'Set The Color To Blue One Time Only
glBegin GL_QUADS 'Draw A Quad

glVertex3f -1.0, 1.0, 0.0 'Top Left
glVertex3f  1.0, 1.0, 0.0 'Top Right
glVertex3f  1.0,-1.0, 0.0 'Bottom Right
glVertex3f-1.0,-1.0,0.0 'Bottom Left

glEnd 'Finished Drawing The Quad

rtri:+0.7 'Increase The Rotation Variable For The Triangle ( New )
rquad:-0.55 'Decrease The Rotation Variable For The Quad     ( New )

Flip

Wend
Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #7 on: March 27, 2009 »
This is how it looks on my computer:



What do you expect it to look like? It looks like it halftones the objects, was that not the expected result?

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #8 on: March 27, 2009 »
This is really odd! My computer shows no effect.

card is Ati radeon Xpress 1100
« Last Edit: March 27, 2009 by Pixel_Outlaw »
Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #9 on: March 27, 2009 »
works fine here as well, this is ment to be a standard opengl feature so it might be driver related, I think both me and zawran have nvidia cards but it should work on an ati :S 

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #10 on: March 28, 2009 »
This really sucks, this was going to be a key component of my project.  :boxer:
In a perfect world everyone would have the same computer.
Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #11 on: March 28, 2009 »
I dont understand why it isnt working, polygon stipple isnt anything super modern, I was under the impression that all basic opengl functions up to 1.1 were in even the software drivers that MS had on windows, really strange its not showing on an modern chipset, even if it is a laptop.  ???

Will give the code a spin on my other pc, that has ati card x1650, and post back what I get.

[EDIT] Well it runs fine on my xp machine with the radeon card so thats good new in one sense but bad news in another as it looks like its something at your end but what i have no idea what, maybe some weird driver error or something.

« Last Edit: March 28, 2009 by TinDragon »

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #12 on: March 29, 2009 »
What exactly are Stipple Polygons?
Those screenshots look like to me as having Gourad Shading
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #13 on: March 29, 2009 »
Quote
What exactly are Stipple Polygons?

Follow the link that Jon have in his post and you will get a good explaination. Its about halfway down the page.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #14 on: March 30, 2009 »
You could maybe try
glEnable(GL_POLYGON_STIPPLE)
after glPolygonStipple()
though it shouldn't make any difference.

Jim
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #15 on: March 31, 2009 »
Ok Jim tried that. No effect.Looks like ATI really dropped the ball on my end.
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [BMAX + OpenGL] Stipple polygons.
« Reply #16 on: March 31, 2009 »
You could use a texture which holds the stipple-pattern in the alpha-channel,
apply texture-coordinates in screenspace (eg. using a projection matrix or glTexGen)
and use alpha-test to reject the "unstippled" fragments.
Challenge Trophies Won: