Merge branch 'gallium-0.1' into gallium-tex-surfaces
[mesa.git] / progs / tests / bug_3101.c
1 /*
2 * (C) Copyright IBM Corporation 2005
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file bug_3101.c
27 *
28 * Simple regression test for bug #3101. Attempt to draw a single square.
29 * After emiting the first vertex, call \c glEdgeFlag to change the vertex
30 * format. If the bug still exists, this will cause a segfault.
31 *
32 * \author Ian Romanick <idr@us.ibm.com>
33 */
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <GL/glut.h>
38
39 static int Width = 400;
40 static int Height = 200;
41 static const GLfloat Near = 5.0, Far = 25.0;
42
43
44 static void Display( void )
45 {
46 glClearColor(0.2, 0.2, 0.8, 0);
47 glClear( GL_COLOR_BUFFER_BIT );
48
49 glPushMatrix();
50
51 /* This is the "reference" square.
52 */
53
54 glTranslatef(-4.5, 0, 0);
55 glBlendEquation( GL_FUNC_ADD );
56 glBlendFunc( GL_ONE, GL_ZERO );
57 glBegin(GL_QUADS);
58 glColor3f( 0.5, 0.5, 0.5 );
59 glVertex2f(-1, -1);
60 glVertex2f( 1, -1);
61 glEdgeFlag(GL_TRUE);
62 glVertex2f( 1, 1);
63 glVertex2f(-1, 1);
64 glEnd();
65
66 glPopMatrix();
67
68 glutSwapBuffers();
69 }
70
71
72 static void Reshape( int width, int height )
73 {
74 GLfloat ar = (float) width / (float) height;
75 Width = width;
76 Height = height;
77 glViewport( 0, 0, width, height );
78 glMatrixMode( GL_PROJECTION );
79 glLoadIdentity();
80 glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
81 glMatrixMode( GL_MODELVIEW );
82 glLoadIdentity();
83 glTranslatef( 0.0, 0.0, -15.0 );
84 }
85
86
87 static void Key( unsigned char key, int x, int y )
88 {
89 (void) x;
90 (void) y;
91 switch (key) {
92 case 27:
93 exit(0);
94 break;
95 }
96 glutPostRedisplay();
97 }
98
99
100 static void Init( void )
101 {
102 const char * const ver_string = (const char * const)
103 glGetString( GL_VERSION );
104
105 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
106 printf("GL_VERSION = %s\n", ver_string);
107
108 printf("\nThis program should draw a single square, but not crash.\n");
109 printf("This is a regression test for bug #3101.\n");
110 printf("https://bugs.freedesktop.org/show_bug.cgi?id=3101\n");
111 glEnable( GL_BLEND );
112 }
113
114
115 int main( int argc, char *argv[] )
116 {
117 glutInit( &argc, argv );
118 glutInitWindowPosition( 0, 0 );
119 glutInitWindowSize( Width, Height );
120 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
121 glutCreateWindow( "Bug #3101 Test" );
122 glutReshapeFunc( Reshape );
123 glutKeyboardFunc( Key );
124 glutDisplayFunc( Display );
125 Init();
126 glutMainLoop();
127 return 0;
128 }