1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"
# $Id: texture.tcl,v 1.2 2009/05/14 20:43:34 vareille Exp $
# Togl - a Tk OpenGL widget
# Copyright (C) 1996 Brian Paul and Ben Bederson
# Copyright (C) 2006-2007 Greg Couch
# See the LICENSE file for copyright details.
# Togl texture map demo
package provide texture 1.0
# add parent directory to path to find Togl's pkgIndex in current directory
if { [file exists pkgIndex.tcl] } {
set auto_path [linsert $auto_path 0 ..]
}
# following load also loads Tk and Togl packages
load [file dirname [info script]]/texture[info sharedlibextension]
# create ::texture namespace
namespace eval ::texture {
}
# Called magnification filter changes
proc ::texture::new_magfilter {} {
global magfilter
mag_filter .f1.view $magfilter
}
# Called minification filter changes
proc ::texture::new_minfilter {} {
global minfilter
min_filter .f1.view $minfilter
}
# Called when texture image radio button changes
proc ::texture::new_image {} {
global image
teximage .f1.view $image
}
# Called when texture S wrap button changes
proc ::texture::new_swrap {} {
global swrap
swrap .f1.view $swrap
}
# Called when texture T wrap button changes
proc ::texture::new_twrap {} {
global twrap
twrap .f1.view $twrap
}
# Called when texture environment radio button selected
proc ::texture::new_env {} {
global envmode
envmode .f1.view $envmode
}
# Called when polygon color sliders change
proc ::texture::new_color { foo } {
global poly_red poly_green poly_blue
polycolor .f1.view $poly_red $poly_green $poly_blue
}
proc ::texture::new_coord_scale { name element op } {
global coord_scale
coord_scale .f1.view $coord_scale
}
proc ::texture::take_photo {} {
image create photo teximg
.f1.view takephoto teximg
teximg write image.ppm -format ppm
}
# Make the widgets
proc ::texture::setup {} {
global magfilter
global minfilter
global image
global swrap
global twrap
global envmode
global poly_red
global poly_green
global poly_blue
global coord_scale
global startx starty # location of mouse when button pressed
global xangle yangle
global xangle0 yangle0
global texscale texscale0
wm title . "Texture Map Options"
### Two frames: top half and bottom half
frame .f1
frame .f2
### The OpenGL window
togl .f1.view -width 250 -height 250 -rgba true -double true -depth true -create create_cb -reshape reshape_cb -display display_cb
### Filter radio buttons
frame .f1.filter -relief ridge -borderwidth 3
frame .f1.filter.mag -relief ridge -borderwidth 2
label .f1.filter.mag.label -text "Magnification Filter" -anchor w
radiobutton .f1.filter.mag.nearest -text GL_NEAREST -anchor w -variable magfilter -value GL_NEAREST -command ::texture::new_magfilter
radiobutton .f1.filter.mag.linear -text GL_LINEAR -anchor w -variable magfilter -value GL_LINEAR -command ::texture::new_magfilter
frame .f1.filter.min -relief ridge -borderwidth 2
label .f1.filter.min.label -text "Minification Filter" -anchor w
radiobutton .f1.filter.min.nearest -text GL_NEAREST -anchor w -variable minfilter -value GL_NEAREST -command ::texture::new_minfilter
radiobutton .f1.filter.min.linear -text GL_LINEAR -anchor w -variable minfilter -value GL_LINEAR -command ::texture::new_minfilter
radiobutton .f1.filter.min.nearest_mipmap_nearest -text GL_NEAREST_MIPMAP_NEAREST -anchor w -variable minfilter -value GL_NEAREST_MIPMAP_NEAREST -command ::texture::new_minfilter
radiobutton .f1.filter.min.linear_mipmap_nearest -text GL_LINEAR_MIPMAP_NEAREST -anchor w -variable minfilter -value GL_LINEAR_MIPMAP_NEAREST -command ::texture::new_minfilter
radiobutton .f1.filter.min.nearest_mipmap_linear -text GL_NEAREST_MIPMAP_LINEAR -anchor w -variable minfilter -value GL_NEAREST_MIPMAP_LINEAR -command ::texture::new_minfilter
radiobutton .f1.filter.min.linear_mipmap_linear -text GL_LINEAR_MIPMAP_LINEAR -anchor w -variable minfilter -value GL_LINEAR_MIPMAP_LINEAR -command ::texture::new_minfilter
pack .f1.filter.mag -fill x
pack .f1.filter.mag.label -fill x
pack .f1.filter.mag.nearest -side top -fill x
pack .f1.filter.mag.linear -side top -fill x
pack .f1.filter.min -fill both -expand true
pack .f1.filter.min.label -side top -fill x
pack .f1.filter.min.nearest -side top -fill x
pack .f1.filter.min.linear -side top -fill x
pack .f1.filter.min.nearest_mipmap_nearest -side top -fill x
pack .f1.filter.min.linear_mipmap_nearest -side top -fill x
pack .f1.filter.min.nearest_mipmap_linear -side top -fill x
pack .f1.filter.min.linear_mipmap_linear -side top -fill x
### Texture coordinate scale and wrapping
frame .f2.coord -relief ridge -borderwidth 3
frame .f2.coord.scale -relief ridge -borderwidth 2
label .f2.coord.scale.label -text "Max Texture Coord" -anchor w
entry .f2.coord.scale.entry -textvariable coord_scale
trace variable coord_scale w ::texture::new_coord_scale
frame .f2.coord.s -relief ridge -borderwidth 2
label .f2.coord.s.label -text "GL_TEXTURE_WRAP_S" -anchor w
radiobutton .f2.coord.s.repeat -text "GL_REPEAT" -anchor w -variable swrap -value GL_REPEAT -command ::texture::new_swrap
radiobutton .f2.coord.s.clamp -text "GL_CLAMP" -anchor w -variable swrap -value GL_CLAMP -command ::texture::new_swrap
frame .f2.coord.t -relief ridge -borderwidth 2
label .f2.coord.t.label -text "GL_TEXTURE_WRAP_T" -anchor w
radiobutton .f2.coord.t.repeat -text "GL_REPEAT" -anchor w -variable twrap -value GL_REPEAT -command ::texture::new_twrap
radiobutton .f2.coord.t.clamp -text "GL_CLAMP" -anchor w -variable twrap -value GL_CLAMP -command ::texture::new_twrap
pack .f2.coord.scale -fill both -expand true
pack .f2.coord.scale.label -side top -fill x
pack .f2.coord.scale.entry -side top -fill x
pack .f2.coord.s -fill x
pack .f2.coord.s.label -side top -fill x
pack .f2.coord.s.repeat -side top -fill x
pack .f2.coord.s.clamp -side top -fill x
pack .f2.coord.t -fill x
pack .f2.coord.t.label -side top -fill x
pack .f2.coord.t.repeat -side top -fill x
pack .f2.coord.t.clamp -side top -fill x
### Texture image radio buttons (just happens to fit into the coord frame)
frame .f2.env -relief ridge -borderwidth 3
frame .f2.env.image -relief ridge -borderwidth 2
label .f2.env.image.label -text "Texture Image" -anchor w
radiobutton .f2.env.image.checker -text "Checker" -anchor w -variable image -value CHECKER -command ::texture::new_image
radiobutton .f2.env.image.tree -text "Tree" -anchor w -variable image -value TREE -command ::texture::new_image
radiobutton .f2.env.image.face -text "Face" -anchor w -variable image -value FACE -command ::texture::new_image
pack .f2.env.image -fill x
pack .f2.env.image.label -side top -fill x
pack .f2.env.image.checker -side top -fill x
pack .f2.env.image.tree -side top -fill x
pack .f2.env.image.face -side top -fill x
### Texture Environment
label .f2.env.label -text "GL_TEXTURE_ENV_MODE" -anchor w
radiobutton .f2.env.modulate -text "GL_MODULATE" -anchor w -variable envmode -value GL_MODULATE -command ::texture::new_env
radiobutton .f2.env.decal -text "GL_DECAL" -anchor w -variable envmode -value GL_DECAL -command ::texture::new_env
radiobutton .f2.env.blend -text "GL_BLEND" -anchor w -variable envmode -value GL_BLEND -command ::texture::new_env
pack .f2.env.label -fill x
pack .f2.env.modulate -side top -fill x
pack .f2.env.decal -side top -fill x
pack .f2.env.blend -side top -fill x
### Polygon color
frame .f2.color -relief ridge -borderwidth 3
label .f2.color.label -text "Polygon color" -anchor w
scale .f2.color.red -label Red -from 0 -to 255 -orient horizontal -variable poly_red -command ::texture::new_color
scale .f2.color.green -label Green -from 0 -to 255 -orient horizontal -variable poly_green -command ::texture::new_color
scale .f2.color.blue -label Blue -from 0 -to 255 -orient horizontal -variable poly_blue -command ::texture::new_color
pack .f2.color.label -fill x
pack .f2.color.red -side top -fill x
pack .f2.color.green -side top -fill x
pack .f2.color.blue -side top -fill x
### Main widgets
pack .f1.view -side left -fill both -expand true
pack .f1.filter -side left -fill y
pack .f1 -side top -fill both -expand true
pack .f2.coord .f2.env -side left -fill both
pack .f2.color -fill x
pack .f2 -side top -fill x
button .photo -text "Take Photo" -command ::texture::take_photo
pack .photo -expand true -fill both
button .quit -text Quit -command exit
pack .quit -expand true -fill both
bind .f1.view <ButtonPress-1> {
set startx %x
set starty %y
set xangle0 $xangle
set yangle0 $yangle
}
bind .f1.view <B1-Motion> {
set xangle [expr $xangle0 + (%x - $startx) / 3.0 ]
set yangle [expr $yangle0 + (%y - $starty) / 3.0 ]
yrot .f1.view $xangle
xrot .f1.view $yangle
}
bind .f1.view <ButtonPress-2> {
set startx %x
set starty %y
set texscale0 $texscale
}
bind .f1.view <B2-Motion> {
set q [ expr ($starty - %y) / 400.0 ]
set texscale [expr $texscale0 * exp($q)]
texscale .f1.view $texscale
}
# set default values:
set minfilter GL_NEAREST_MIPMAP_LINEAR
set magfilter GL_LINEAR
set swrap GL_REPEAT
set twrap GL_REPEAT
set envmode GL_MODULATE
set image CHECKER
set poly_red 255
set poly_green 255
set poly_blue 255
set coord_scale 1.0
set xangle 0.0
set yangle 0.0
set texscale 1.0
}
# Execution starts here!
if { [info script] == $argv0 } {
::texture::setup
}
|