Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bug_3101.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. * \file bug_3101.c
  26. *
  27. * Simple regression test for bug #3101. Attempt to draw a single square.
  28. * After emiting the first vertex, call \c glEdgeFlag to change the vertex
  29. * format. If the bug still exists, this will cause a segfault.
  30. *
  31. * \author Ian Romanick <idr@us.ibm.com>
  32. */
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <GL/glut.h>
  36. static int Width = 400;
  37. static int Height = 200;
  38. static const GLfloat Near = 5.0, Far = 25.0;
  39. static void Display( void )
  40. {
  41. glClearColor(0.2, 0.2, 0.8, 0);
  42. glClear( GL_COLOR_BUFFER_BIT );
  43. glPushMatrix();
  44. /* This is the "reference" square.
  45. */
  46. glTranslatef(-4.5, 0, 0);
  47. glBlendEquation( GL_FUNC_ADD );
  48. glBlendFunc( GL_ONE, GL_ZERO );
  49. glBegin(GL_QUADS);
  50. glColor3f( 0.5, 0.5, 0.5 );
  51. glVertex2f(-1, -1);
  52. glVertex2f( 1, -1);
  53. glEdgeFlag(GL_TRUE);
  54. glVertex2f( 1, 1);
  55. glVertex2f(-1, 1);
  56. glEnd();
  57. glPopMatrix();
  58. glutSwapBuffers();
  59. }
  60. static void Reshape( int width, int height )
  61. {
  62. GLfloat ar = (float) width / (float) height;
  63. Width = width;
  64. Height = height;
  65. glViewport( 0, 0, width, height );
  66. glMatrixMode( GL_PROJECTION );
  67. glLoadIdentity();
  68. glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
  69. glMatrixMode( GL_MODELVIEW );
  70. glLoadIdentity();
  71. glTranslatef( 0.0, 0.0, -15.0 );
  72. }
  73. static void Key( unsigned char key, int x, int y )
  74. {
  75. (void) x;
  76. (void) y;
  77. switch (key) {
  78. case 27:
  79. exit(0);
  80. break;
  81. }
  82. glutPostRedisplay();
  83. }
  84. static void Init( void )
  85. {
  86. const char * const ver_string = (const char * const)
  87. glGetString( GL_VERSION );
  88. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  89. printf("GL_VERSION = %s\n", ver_string);
  90. printf("\nThis program should draw a single square, but not crash.\n");
  91. printf("This is a regression test for bug #3101.\n");
  92. printf("https://bugs.freedesktop.org/show_bug.cgi?id=3101\n");
  93. glEnable( GL_BLEND );
  94. }
  95. int main( int argc, char *argv[] )
  96. {
  97. glutInit( &argc, argv );
  98. glutInitWindowPosition( 0, 0 );
  99. glutInitWindowSize( Width, Height );
  100. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  101. glutCreateWindow( "Bug #3101 Test" );
  102. glutReshapeFunc( Reshape );
  103. glutKeyboardFunc( Key );
  104. glutDisplayFunc( Display );
  105. Init();
  106. glutMainLoop();
  107. return 0;
  108. }