<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>Shakaran &#187; OpenGL</title> <atom:link href="http://shakaran.net/blog/category/OpenGL/feed/" rel="self" type="application/rss+xml" /><link>http://shakaran.net/blog</link> <description>Blog de un estudiante de ingeniería informática y sysadmin</description> <lastBuildDate>Fri, 20 Jan 2012 01:04:24 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <image><link>http://shakaran.net/blog</link> <url>http://www.shakaran.net/blog/wp-content/favicon.png</url><title>Shakaran</title> </image> <item><title>Menús y cambio de formas geométricas con OpenGL</title><link>http://shakaran.net/blog/2009/02/menus-y-cambio-de-formas-geometricas-con-opengl/</link> <comments>http://shakaran.net/blog/2009/02/menus-y-cambio-de-formas-geometricas-con-opengl/#comments</comments> <pubDate>Thu, 12 Feb 2009 03:06:17 +0000</pubDate> <dc:creator>shakaran</dc:creator> <category><![CDATA[OpenGL]]></category> <category><![CDATA[cambio]]></category> <category><![CDATA[color]]></category> <category><![CDATA[ejemplo]]></category> <category><![CDATA[example]]></category> <category><![CDATA[geometrico]]></category> <category><![CDATA[keyboard]]></category> <category><![CDATA[menus]]></category> <category><![CDATA[triangulos]]></category> <category><![CDATA[ventanas]]></category><guid isPermaLink="false">http://shakaran.net/blog/?p=266</guid> <description><![CDATA[OpenGL es un librería de gráficos bastante versátil. En este artículo vamos a ver un pequeño ejemplo de su potencial. El ejemplo consiste en dibujar un triángulo blanco en una ventana y que al pulsar la tecla &#8216;c&#8217; nuestro triángulo se coloree de rojo, verde y blanco en cada vértice. Por otro lado si pulsamos [...]<br /><div><img src="http://shakaran.net/blog/wp-content/plugins/gd-star-rating/gfx.php?value=4.0" /></div><div>Rating: 4.0/<strong>10</strong> (3 votes cast)</div><br />]]></description> <content:encoded><![CDATA[<div class="wpbuzzer_button" style="float: right"><a title="Post on Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="normal-button" data-url="http://shakaran.net/blog/2009/02/menus-y-cambio-de-formas-geometricas-con-opengl/" data-imageurl=""></a><script type="text/javascript" src="http://www.google.com/buzz/api/button.js"></script></div><p style="text-align: justify;"><a href="http://www.opengl.org" target="_blank">OpenGL</a> es un <strong>librería de gráficos</strong> bastante versátil. En este artículo vamos a ver un pequeño ejemplo de su potencial.</p><p style="text-align: justify;">El ejemplo consiste en <strong>dibujar un triángulo blanco</strong> en una ventana y que al pulsar la tecla &#8216;c&#8217; nuestro triángulo se coloree de rojo, verde y blanco en cada vértice. Por otro lado si pulsamos la tecla escape &#8216;Esc&#8217; la aplicación terminará. Además <strong>añadiremos un pequeño menú</strong> que se accionara al pulsar el botón derecho del ratón, donde tendremos la opción de cambiar de modo y salir.</p><p style="text-align: justify;">Una pequeña imagen que detalla el proceso:</p><div id="attachment_267" class="wp-caption aligncenter" style="width: 512px"><img class="size-full wp-image-267" title="opengl-triangulos-ejemplo" src="http://shakaran.net/blog/wp-content/uploads/2009/02/opengl-triangulos-ejemplo.png" alt="opengl-triangulos-ejemplo" width="502" height="272" /><p class="wp-caption-text">Ejemplo sencillo con OpenGL</p></div><p>A continuación pongo el código y más adelante lo detallo paso a paso:</p><div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Descargar <a href="http://shakaran.net/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=266&amp;download=ejercicio.c">ejercicio.c</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2664"><td class="line_numbers"><pre>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
</pre></td><td class="code" id="p266code4"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt; stdio.h &gt;;</span>
<span style="color: #339933;">#include &lt; stdlib.h &gt;;</span>
<span style="color: #339933;">#include &lt; GL/glut.h &gt;;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">enum</span> <span style="color: #009900;">&#123;</span>
Â  MENU_CHANGE <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>
Â  MENU_EXIT
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> mode <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> SelectFromMenu<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> idCommand<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>Â Â 
Â Â Â  <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>idCommand<span style="color: #009900;">&#41;</span>
Â Â Â  <span style="color: #009900;">&#123;</span>
Â Â Â Â Â Â Â  <span style="color: #b1b100;">case</span> MENU_CHANGE<span style="color: #339933;">:</span>
Â Â Â Â Â Â Â Â Â Â Â  mode <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>mode <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">:</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
Â Â Â Â Â Â Â Â Â Â Â  glutPostRedisplay<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â Â Â Â Â Â Â Â Â  <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
Â Â Â Â Â Â Â  <span style="color: #b1b100;">case</span> MENU_EXIT<span style="color: #339933;">:</span>
Â Â Â Â Â Â Â Â Â Â Â  exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â Â Â Â Â Â Â Â Â  <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
Â Â Â  <span style="color: #009900;">&#125;</span>
Â Â Â  glutPostRedisplay<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> Keyboard<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> key<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> x<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> y<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
Â Â Â  <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span>
Â Â Â  <span style="color: #009900;">&#123;</span>
Â Â Â Â Â Â Â  <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">27</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// ESCAPE key</span>
Â Â Â Â Â Â Â Â Â Â Â  exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â Â Â Â Â Â Â Â Â  <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
Â Â Â Â Â Â Â  <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'c'</span><span style="color: #339933;">:</span>
Â Â Â Â Â Â Â Â Â Â Â  SelectFromMenu<span style="color: #009900;">&#40;</span>MENU_CHANGE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â Â Â Â Â Â Â Â Â  <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
Â Â Â  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> buildPopupMenu<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
Â Â Â  <span style="color: #993333;">int</span> menu <span style="color: #339933;">=</span> glutCreateMenu<span style="color: #009900;">&#40;</span>SelectFromMenu<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glutAddMenuEntry<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Cambiar modo<span style="color: #000099; font-weight: bold;">\t</span>c&quot;</span><span style="color: #339933;">,</span> MENU_CHANGE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glutAddMenuEntry<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Salir<span style="color: #000099; font-weight: bold;">\t</span>Esc&quot;</span><span style="color: #339933;">,</span> MENU_EXIT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Â Â Â  <span style="color: #b1b100;">return</span> menu<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> display <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
Â Â Â  glClear<span style="color: #009900;">&#40;</span>GL_COLOR_BUFFER_BIT <span style="color: #339933;">|</span> GL_DEPTH_BUFFER_BIT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glLoadIdentity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glTranslatef<span style="color: #009900;">&#40;</span><span style="color:#800080;">0.0</span><span style="color: #339933;">,</span> <span style="color:#800080;">0.0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color:#800080;">4.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
Â Â Â  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>mode <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
Â Â Â  <span style="color: #009900;">&#123;</span>
Â Â Â Â Â Â Â  glBegin<span style="color: #009900;">&#40;</span>GL_TRIANGLES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Â Â Â Â Â Â Â Â Â Â Â  glColor3f <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span>.<span style="color: #202020;">f</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span>.<span style="color: #202020;">f</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span>.<span style="color: #202020;">f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>Â Â Â  <span style="color: #666666; font-style: italic;">// White colour</span>
Â Â Â Â Â Â Â Â Â Â Â  glVertex3f<span style="color: #009900;">&#40;</span><span style="color:#800080;">0.0</span><span style="color: #339933;">,</span> <span style="color:#800080;">1.0</span><span style="color: #339933;">,</span> <span style="color:#800080;">0.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â Â Â Â Â Â Â Â Â  glVertex3f<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color:#800080;">1.0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color:#800080;">1.0</span><span style="color: #339933;">,</span> <span style="color:#800080;">0.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â Â Â Â Â Â Â Â Â  glVertex3f<span style="color: #009900;">&#40;</span><span style="color:#800080;">1.0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color:#800080;">1.0</span><span style="color: #339933;">,</span> <span style="color:#800080;">0.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Â Â Â Â Â Â Â  glEnd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  <span style="color: #009900;">&#125;</span>
Â Â Â  <span style="color: #b1b100;">else</span>
Â Â Â  <span style="color: #009900;">&#123;</span>
Â Â Â Â Â Â Â  glBegin<span style="color: #009900;">&#40;</span>GL_TRIANGLES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Â Â Â Â Â Â Â Â Â Â Â  glColor3f <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span>.<span style="color: #202020;">f</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span>.<span style="color: #202020;">f</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span>.<span style="color: #202020;">f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>Â Â Â  <span style="color: #666666; font-style: italic;">// Green colour</span>
Â Â Â Â Â Â Â Â Â Â Â  glVertex3f<span style="color: #009900;">&#40;</span><span style="color:#800080;">0.0</span><span style="color: #339933;">,</span> <span style="color:#800080;">1.0</span><span style="color: #339933;">,</span> <span style="color:#800080;">0.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Â Â Â Â Â Â Â Â Â Â Â  glColor3f <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span>.<span style="color: #202020;">f</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span>.<span style="color: #202020;">f</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span>.<span style="color: #202020;">f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>Â Â Â  <span style="color: #666666; font-style: italic;">// White colour</span>
Â Â Â Â Â Â Â Â Â Â Â  glVertex3f<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color:#800080;">1.0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color:#800080;">1.0</span><span style="color: #339933;">,</span> <span style="color:#800080;">0.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Â Â Â Â Â Â Â Â Â Â Â  glColor3f <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span>.<span style="color: #202020;">f</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span>.<span style="color: #202020;">f</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span>.<span style="color: #202020;">f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>Â Â Â  <span style="color: #666666; font-style: italic;">// Red colour</span>
Â Â Â Â Â Â Â Â Â Â Â  glVertex3f<span style="color: #009900;">&#40;</span><span style="color:#800080;">1.0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color:#800080;">1.0</span><span style="color: #339933;">,</span> <span style="color:#800080;">0.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Â Â Â Â Â Â Â  glEnd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  <span style="color: #009900;">&#125;</span>
&nbsp;
Â Â Â  glutSwapBuffers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> resize <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> w<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> h<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
Â Â Â  glViewport<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> w<span style="color: #339933;">,</span> h<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glMatrixMode<span style="color: #009900;">&#40;</span>GL_PROJECTION<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glLoadIdentity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  gluPerspective<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">50</span>.<span style="color: #339933;">,</span> w<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span>h<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span>.<span style="color: #339933;">,</span> <span style="color: #0000dd;">10</span>.<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glMatrixMode<span style="color: #009900;">&#40;</span>GL_MODELVIEW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> init <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
Â Â Â  glEnable<span style="color: #009900;">&#40;</span>GL_DEPTH_TEST<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
Â Â Â  glutInit<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>argc<span style="color: #339933;">,</span> argv<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glutInitDisplayMode<span style="color: #009900;">&#40;</span>GLUT_DOUBLE <span style="color: #339933;">|</span> GLUT_RGB<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glutInitWindowSize<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">400</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glutInitWindowPosition<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">200</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glutCreateWindow<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Ejercicio&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glutDisplayFunc<span style="color: #009900;">&#40;</span>display<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glutReshapeFunc<span style="color: #009900;">&#40;</span>resize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glutKeyboardFunc<span style="color: #009900;">&#40;</span>Keyboard<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Â Â Â  buildPopupMenu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Â Â Â  glutAttachMenu<span style="color: #009900;">&#40;</span>GLUT_RIGHT_BUTTON<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Â Â Â  glutMainLoop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Â Â Â  <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p style="text-align: justify;">El <strong>funcionamiento principal</strong>, es tener una función display(), que según en el modo que estemos, dibujara una u otra figura (coloreada de una manera u otra). Para ello utilizaremos una variable global estática con la que<strong> guardaremos el modo</strong> en el que estamos, cuando se requiera redibujar, miraremos el modo y lo cambiaremos y dibujaremos la nueva figura. Las funcion de keyboard() llamará al menu según la tecla (salir o cambiar modo) y <strong>el menú se encargara de llamar a display</strong> y cambiar el modo.</p><p style="text-align: justify;">De forma más detalla en la funcion main() primero pasamos los argumentos de entrada con glutInit() y inicializamos glutInitDisplaymode con un <strong>doble buffer y RGB</strong>, ya que necesitaremos un buffer doble para que nuestras figuras se rendericen en un frame y mientras en otro se procesen.</p><p style="text-align: justify;">Le damos un <strong>tamaño a la ventana</strong> de 400&#215;400 con glutInitWindowSize() y en la posición 200&#215;200 con un título de ventana &#8220;Ejercicio&#8221;. y llamamos a la función init para que active la prueba de profundidad.</p><p style="text-align: justify;">Luego asignamos una funcion de retrollamada (callback) para mostrar nuestra ventana con lgutDiplayFunc(), la <strong>función de retrollamada</strong> sera display(), que la veremos más adelante.</p><p style="text-align: justify;">Otra función de retrollamada para cuando <strong>redimensionemos la ventana</strong> y despues llamaremos a buildPopupMenu() que sera una función para construir nuestro menú.</p><p style="text-align: justify;">Y adjuntaremos el menú cuando se presione <strong>el botón derecho </strong>del ratón con glutAttachmenu(). Despues llamamos al bucle principal de glut.</p><p style="text-align: justify;"><span style="text-decoration: underline;"><strong>Nota</strong></span>: algo importante a resaltar, si utilizas una <span style="text-decoration: underline;"><strong>tarjeta gráfica ATI,</strong></span> es posible que tengas algun fallo si pones la línea, ya que el buffer no quedara totalmente limpio al dibujar en pantalla:</p><div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p266code5'); return false;">Ver código</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2665"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p266code5"><pre class="c" style="font-family:monospace;"> glClear<span style="color: #009900;">&#40;</span>GL_COLOR_BUFFER_BIT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>Por eso es mejor ponerlo así y <strong>evitamos este tipo de fallos</strong> (desconozco si en otras tarjetas se da dicho fallo):</p><div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p266code6'); return false;">Ver código</a> C</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2666"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p266code6"><pre class="c" style="font-family:monospace;">glClear<span style="color: #009900;">&#40;</span>GL_COLOR_BUFFER_BIT <span style="color: #339933;">|</span> GL_DEPTH_BUFFER_BIT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p style="text-align: justify;">Para compilar:</p><pre line="1" lang="shell" file="compilar.txt" style="text-align: justify;">gcc -lGL -lGLU -lglut ejercicio.c -o ejercicio</pre><p style="text-align: justify;">Y ejecutarlo:</p><pre line="1" lang="shell" file="ejecutar.txt" style="text-align: justify;">./ejercicio</pre><p style="text-align: justify;">¿Te ha gustado o resultado útil? Pues <strong>deja un comentario</strong> con tu opinión <img src='http://shakaran.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p> <br /><div><img src="http://shakaran.net/blog/wp-content/plugins/gd-star-rating/gfx.php?value=4.0" /></div><div>Rating: 4.0/<strong>10</strong> (3 votes cast)</div><br />]]></content:encoded> <wfw:commentRss>http://shakaran.net/blog/2009/02/menus-y-cambio-de-formas-geometricas-con-opengl/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using memcached
Page Caching using memcached
Database Caching 10/35 queries in 0.061 seconds using memcached
Object Caching 962/982 objects using memcached

Served from: shakaran.net @ 2012-02-04 22:17:48 -->
