bug_3101.c revision 32001f49
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/glew.h>
38#include "glut_wrap.h"
39
40static int Width = 400;
41static int Height = 200;
42static const GLfloat Near = 5.0, Far = 25.0;
43
44
45static void Display( void )
46{
47   glClearColor(0.2, 0.2, 0.8, 0);
48   glClear( GL_COLOR_BUFFER_BIT );
49
50   glPushMatrix();
51
52   /* This is the "reference" square.
53    */
54
55   glTranslatef(-4.5, 0, 0);
56   glBlendEquation( GL_FUNC_ADD );
57   glBlendFunc( GL_ONE, GL_ZERO );
58   glBegin(GL_QUADS);
59   glColor3f( 0.5, 0.5, 0.5 );
60   glVertex2f(-1, -1);
61   glVertex2f( 1, -1);
62   glEdgeFlag(GL_TRUE);
63   glVertex2f( 1,  1);
64   glVertex2f(-1,  1);
65   glEnd();
66
67   glPopMatrix();
68
69   glutSwapBuffers();
70}
71
72
73static void Reshape( int width, int height )
74{
75   GLfloat ar = (float) width / (float) height;
76   Width = width;
77   Height = height;
78   glViewport( 0, 0, width, height );
79   glMatrixMode( GL_PROJECTION );
80   glLoadIdentity();
81   glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
82   glMatrixMode( GL_MODELVIEW );
83   glLoadIdentity();
84   glTranslatef( 0.0, 0.0, -15.0 );
85}
86
87
88static void Key( unsigned char key, int x, int y )
89{
90   (void) x;
91   (void) y;
92   switch (key) {
93      case 27:
94         exit(0);
95         break;
96   }
97   glutPostRedisplay();
98}
99
100
101static void Init( void )
102{
103   const char * const ver_string = (const char *)
104       glGetString( GL_VERSION );
105
106   printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
107   printf("GL_VERSION = %s\n", ver_string);
108
109   printf("\nThis program should draw a single square, but not crash.\n");
110   printf("This is a regression test for bug #3101.\n");
111   printf("https://bugs.freedesktop.org/show_bug.cgi?id=3101\n");
112   glEnable( GL_BLEND );
113}
114
115
116int main( int argc, char *argv[] )
117{
118   glutInit( &argc, argv );
119   glutInitWindowPosition( 0, 0 );
120   glutInitWindowSize( Width, Height );
121   glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
122   glutCreateWindow( "Bug #3101 Test" );
123   glewInit();
124   glutReshapeFunc( Reshape );
125   glutKeyboardFunc( Key );
126   glutDisplayFunc( Display );
127   Init();
128   glutMainLoop();
129   return 0;
130}
131