Exemple #1
0
void fini_brush(int i)
{
    struct brush *b = get_brush(i);

    if (b->state == 1)
    {
        /* Finalize any vertex and fragment shader objects. */

        if (GL_has_shader_objects)
        {
            if (b->shad_prog) glDeleteObjectARB(b->shad_prog);
            if (b->vert_shad) glDeleteObjectARB(b->vert_shad);
            if (b->frag_shad) glDeleteObjectARB(b->frag_shad);
        }
                
        /* Finalize any vertex and fragment programs. */

        if (GL_has_vertex_program)
            if (glIsProgramARB(b->vert_prog))
                glDeleteProgramsARB(1, &b->vert_prog);

        if (GL_has_fragment_program)
            if (glIsProgramARB(b->frag_prog))
                glDeleteProgramsARB(1, &b->frag_prog);
                
        b->vert_shad = 0;
        b->frag_shad = 0;
        b->shad_prog = 0;

        b->vert_prog = 0;
        b->frag_prog = 0;
        b->state     = 0;
    }
}
static void Init( void )
{
   GLint errno;
   GLuint prognum;
   
   static const char *prog1 =
      "!!ARBvp1.0\n"
      "MOV  result.color, vertex.color;\n"
/*       "MOV  result.color, {0,0,0,1};\n"  */
      "MOV  result.position, vertex.position;\n"
      "END\n";


   glGenProgramsARB(1, &prognum);

   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
		      strlen(prog1), (const GLubyte *) prog1);

   assert(glIsProgramARB(prognum));
   errno = glGetError();
   printf("glGetError = %d\n", errno);
   if (errno != GL_NO_ERROR)
   {
      GLint errorpos;

      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
      printf("errorpos: %d\n", errorpos);
      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
   }
}
static void Init( void )
{
   GLint errno;
   GLuint prognum;
   
   static const char *prog1 =
      "!!ARBvp1.0\n"
      "MOV  result.color, vertex.color;\n"
      "MOV  result.position, vertex.position;\n"
      "END\n";

   glGenProgramsARB(1, &prognum);
   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
		      strlen(prog1), (const GLubyte *) prog1);

   assert(glIsProgramARB(prognum));
   errno = glGetError();
   printf("glGetError = %d\n", errno);
   if (errno != GL_NO_ERROR)
   {
      GLint errorpos;

      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
      printf("errorpos: %d\n", errorpos);
      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
   }


   glEnableClientState( GL_VERTEX_ARRAY );
   glEnableClientState( GL_COLOR_ARRAY );
   glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts );
   glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color );

}
Exemple #4
0
static void load_program(const char *prog, GLuint prognum)
{
   int a;	
   GLint errorpos, errno;
   
   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                        strlen(prog), (const GLubyte *) prog);

   assert(glIsProgramARB(prognum));
   errno = glGetError();
   printf("glGetError = %d\n", errno);
   if (errno != GL_NO_ERROR)
   {
      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
      printf("errorpos: %d\n", errorpos);
      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));

      for (a=-10; a<10; a++)
      {
         if ((errorpos+a < 0) || (errorpos+a >= strlen(prog))) continue;	      
         printf("%c", prog[errorpos+a]);
      }	  
      printf("\n");      
      exit(1);
   }
}
void
piglit_init(int argc, char **argv)
{
	static const char * program =
		"!!ARBvp1.0\n"
		"MOV result.color, vertex.color;\n"
		"MOV result.position, vertex.position;\n"
		"END\n";
	GLuint program_no;

	piglit_require_extension("GL_ARB_draw_elements_base_vertex");
	piglit_require_extension("GL_ARB_vertex_program");
	glGenProgramsARB(1, &program_no);
	glBindProgramARB(GL_VERTEX_PROGRAM_ARB, program_no);
	glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
			strlen(program), program);
	assert(glIsProgramARB(program_no));

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, sizeof(vertices[0]), vertices);
	glEnableClientState(GL_COLOR_ARRAY);
	glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
}
Exemple #6
0
static void Init( void )
{
   static const char *modulate2D =
      "!!ARBfp1.0\n"
      "TEMP R0;\n"
      "TEX R0, fragment.texcoord[0], texture[0], 2D; \n"
      "MUL result.color, R0, fragment.color; \n"
      "END"
      ;
   GLuint modulateProg;
   GLuint Texture;

   if (!glutExtensionSupported("GL_ARB_fragment_program")) {
      printf("Error: GL_ARB_fragment_program not supported!\n");
      exit(1);
   }
   printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));

   /* Setup the fragment program */
   glGenProgramsARB(1, &modulateProg);
   glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
   glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                        strlen(modulate2D), (const GLubyte *)modulate2D);

   printf("glGetError = 0x%x\n", (int) glGetError());
   printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
          (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
   assert(glIsProgramARB(modulateProg));

   glEnable(GL_FRAGMENT_PROGRAM_ARB);

   /* Load texture */
   glGenTextures(1, &Texture);
   glBindTexture(GL_TEXTURE_2D, Texture);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
      printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE);
      exit(1);
   }
   /* XXX this enable shouldn't really be needed!!! */
   glEnable(GL_TEXTURE_2D);

   glClearColor(.3, .3, .3, 0);
}
static void Init( void )
{
   GLint errno;
   GLuint prognum;
   GLint i;

   static const char *prog1 =
      "!!ARBvp1.0\n"
      "MOV  result.color, {1.0}.xxxx;\n"
      "MOV  result.position, vertex.position;\n"
      "END\n";

   glGenProgramsARB(1, &prognum);
   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
		      strlen(prog1), (const GLubyte *) prog1);

   assert(glIsProgramARB(prognum));
   errno = glGetError();
   printf("glGetError = %d\n", errno);
   if (errno != GL_NO_ERROR)
   {
      GLint errorpos;

      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
      printf("errorpos: %d\n", errorpos);
      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
   }


   glEnableClientState( GL_VERTEX_ARRAY );
   glEnableClientState( GL_COLOR_ARRAY );
   glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts );


   for (i = 0; i < NR_VERTS; i++) {
      verts[i][0] = cos(i / (float)NR_VERTS * 2.0 * 3.141592);
      verts[i][1] = sin(i / (float)NR_VERTS * 2.0 * 3.141592);
      verts[i][2] = 0.0;
      verts[i][3] = 1.0;

      indices[2*i+0] = i;
      indices[2*i+1] = (i+1 == NR_VERTS) ? 0 : i+1;
   }
}
Exemple #8
0
static void Init( void )
{
   GLint errnum;
   GLuint prognum;
   
   static const char *prog1 =
      "!!ARBvp1.0\n"
      "MOV  result.color, vertex.color;\n"
      "MOV  result.position, vertex.position;\n"
      "END\n";


   glGenProgramsARB(1, &prognum);

   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
		      strlen(prog1), (const GLubyte *) prog1);

   assert(glIsProgramARB(prognum));
   errnum = glGetError();
   printf("glGetError = %d\n", errnum);
   if (errnum != GL_NO_ERROR)
   {
      GLint errorpos;

      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
      printf("errorpos: %d\n", errorpos);
      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
   }


   glEnableClientState( GL_VERTEX_ARRAY );
   glEnableClientState( GL_COLOR_ARRAY );

   glGenBuffersARB(1, &arrayObj);
   glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj);
   glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts, GL_STATIC_DRAW_ARB);

   glVertexPointer( 4, GL_FLOAT, sizeof(verts[0]), 0 );
   glColorPointer( 4, GL_FLOAT, sizeof(verts[0]), (void *)(4*sizeof(float)) );
}
static void Init( int argc, char *argv[] )
{
   const char *file;
   const GLfloat yuvtorgb[16] = {
      1.164,   1.164,    1.164,      0,
      0,       -.391,    2.018,      0,
      1.596,   -.813,    0.0,        0,
      (-.0625*1.164 + -.5*1.596),     (-.0625*1.164 + -.5*-.813 + -.5*-.391),     (-.0625*1.164 + -.5*2.018),      1  
   };

   if (!glutExtensionSupported("GL_ARB_fragment_program")) {
      printf("Error: GL_ARB_fragment_program not supported!\n");
      exit(1);
   }

   if (!glutExtensionSupported("GL_EXT_422_pixels")) {
      printf("Error: GL_EXT_422_pixels not supported!\n");
      exit(1);
   }

   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

   file = TEXTURE_FILE;

   /* Load the texture as YCbCr.
    */
   glBindTexture(GL_TEXTURE_2D, yuvObj);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

   ImageYUV = LoadYUVImage(file, &ImgWidth, &ImgHeight );
   if (!ImageYUV) {
      printf("Couldn't read %s\n", TEXTURE_FILE);
      exit(0);
   }

   glTexImage2D(GL_TEXTURE_2D, 0,
		GL_RGB,
		ImgWidth, ImgHeight, 0,
		GL_422_EXT,
		GL_UNSIGNED_BYTE, ImageYUV); 

   glEnable(GL_TEXTURE_2D);

   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

   {
      static const char *modulateYUV =
	 "!!ARBfp1.0\n"
	 "TEMP R0;\n"
	 "TEX R0, fragment.texcoord[0], texture[0], 2D; \n"

  	 "ADD R0, R0, {-0.0625, -0.5, -0.5, 0.0}; \n"
   	 "DP3 result.color.x, R0, {1.164,  1.596,  0.0}; \n"   
  	 "DP3 result.color.y, R0, {1.164, -0.813, -0.391}; \n" 
  	 "DP3 result.color.z, R0, {1.164,  0.0,    2.018}; \n" 
  	 "MOV result.color.w, R0.w; \n"  

	 "END"
	 ;

      GLuint modulateProg;


      /* Setup the fragment program */
      glGenProgramsARB(1, &modulateProg);
      glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
      glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
			 strlen(modulateYUV), (const GLubyte *)modulateYUV);

      printf("glGetError = 0x%x\n", (int) glGetError());
      printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
	     (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
      assert(glIsProgramARB(modulateProg));

   }

   /* Now the same, but use a color matrix to do the conversion at
    * upload time:
    */
   glBindTexture(GL_TEXTURE_2D, rgbObj);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

   glMatrixMode( GL_COLOR_MATRIX );
   glLoadMatrixf( yuvtorgb );
   
   glTexImage2D(GL_TEXTURE_2D, 0,
                GL_RGB,
		ImgWidth, ImgHeight, 0,
                GL_422_EXT,
		GL_UNSIGNED_BYTE, ImageYUV);

   glLoadIdentity();
   glMatrixMode( GL_MODELVIEW );

   glEnable(GL_TEXTURE_2D);

   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);


   glShadeModel(GL_FLAT);
   glClearColor(0.3, 0.3, 0.4, 1.0);
}
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_ARBProgram_nglIsProgramARB(JNIEnv *env, jclass clazz, jint program, jlong function_pointer) {
	glIsProgramARBPROC glIsProgramARB = (glIsProgramARBPROC)((intptr_t)function_pointer);
	GLboolean __result = glIsProgramARB(program);
	return __result;
}
Exemple #11
0
static void Init( void )
{
   GLint errno;
   GLuint prognum;
   char buf[16 * 1024];
   GLuint sz;
   FILE *f;

   if ((f = fopen(filename, "r")) == NULL) {
      fprintf(stderr, "couldn't open %s\n", filename);
      exit(1);
   }

   sz = (GLuint) fread(buf, 1, sizeof(buf) - 1, f);
   buf[sizeof(buf) - 1] = '\0';
   if (!feof(f)) {
      fprintf(stderr, "file too long\n");
      fclose(f);
      exit(1);
   }

   fclose(f);
   fprintf(stderr, "%.*s\n", sz, buf);

   if (strncmp( buf, "!!VP", 4 ) == 0) {
      glEnable( GL_VERTEX_PROGRAM_NV );
      glGenProgramsNV( 1, &prognum );
      glBindProgramNV( GL_VERTEX_PROGRAM_NV, prognum );
      glLoadProgramNV( GL_VERTEX_PROGRAM_NV, prognum, sz, (const GLubyte *) buf );
      assert( glIsProgramNV( prognum ) );
   }
   else {
      glEnable(GL_VERTEX_PROGRAM_ARB);

      glGenProgramsARB(1, &prognum);

      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
      glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
		        sz, (const GLubyte *) buf);
      if (glGetError()) {
         printf("Program failed to compile:\n%s\n", buf);
         printf("Error: %s\n",
                (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
         exit(1);
      }
      assert(glIsProgramARB(prognum));
   }

   errno = glGetError();
   printf("glGetError = %d\n", errno);
   if (errno != GL_NO_ERROR)
   {
      GLint errorpos;

      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
      printf("errorpos: %d\n", errorpos);
      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
   }

   {
      const float Ambient[4] = { 0.0, 1.0, 0.0, 0.0 };
      const float Diffuse[4] = { 1.0, 0.0, 0.0, 0.0 };
      const float Specular[4] = { 0.0, 0.0, 1.0, 0.0 };
      const float Emission[4] = { 0.0, 0.0, 0.0, 1.0 };
      glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, Ambient);
      glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Diffuse);
      glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Specular);
      glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Emission);
   }
}
static void Init( void )
{
   GLint errno;
   GLuint prognum;
   int color_size = 4;

   static const char *prog1 =
      "!!ARBvp1.0\n"
      "PARAM mvp[4] = {state.matrix.mvp};\n"
      "DP4 result.position.x, vertex.position, mvp[0]; \n"
      "DP4 result.position.y, vertex.position, mvp[1]; \n"
      "DP4 result.position.z, vertex.position, mvp[2]; \n"
      "DP4 result.position.w, vertex.position, mvp[3]; \n"
      "MOV  result.color, vertex.color;\n"
      "END\n";

#ifndef GL_ARB_vertex_type_2_10_10_10_rev
   fprintf(stderr,"built without ARB_vertex_type_2_10_10_10_rev\n");
   exit(1);
#endif

  if (!glutExtensionSupported("GL_ARB_vertex_type_2_10_10_10_rev")){
     fprintf(stderr,"requires ARB_vertex_type_2_10_10_10_rev\n");
     exit(1);
   }

   glGenProgramsARB(1, &prognum);
   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
		      strlen(prog1), (const GLubyte *) prog1);

   assert(glIsProgramARB(prognum));
   errno = glGetError();

   if (errno != GL_NO_ERROR)
   {
      GLint errorpos;

      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
      printf("errorpos: %d\n", errorpos);
      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
   }


   glEnableClientState( GL_VERTEX_ARRAY );
   glEnableClientState( GL_COLOR_ARRAY );

   SetupVerts();

   glGenBuffersARB(1, &arrayObj);
   glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj);
   glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts, GL_STATIC_DRAW_ARB);

   if (bgra)
     color_size = GL_BGRA;

#ifdef GL_ARB_vertex_type_2_10_10_10_rev
   glVertexPointer( 4, GL_INT_2_10_10_10_REV, sizeof(verts[0]), 0 );
   glColorPointer( color_size, GL_UNSIGNED_INT_2_10_10_10_REV, sizeof(verts[0]), (void *)(sizeof(unsigned int)) );
#endif
}
Exemple #13
0
static void Init( void )
{
   GLint errno;
   GLuint prognum, fprognum;
	
   static const char prog[] = 
      "!!ARBvp1.0\n"
      "DP4   result.position.x, state.matrix.mvp.row[0], vertex.position ;\n"
      "DP4   result.position.y, state.matrix.mvp.row[1], vertex.position ;\n"
      "DP4   result.position.z, state.matrix.mvp.row[2], vertex.position ;\n"
      "DP4   result.position.w, state.matrix.mvp.row[3], vertex.position ;\n"
      "MOV   result.color.front.primary,   {.5, .5, .5, 1};\n"		
      "MOV   result.color.front.secondary, {1, 1, 1, 1};\n"
      "END";

    static const char fprog[] = 
      "!!ARBfp1.0\n"			  
      "MOV result.color, fragment.color.secondary;\n"
      "END";

   if (!glutExtensionSupported("GL_ARB_vertex_program")) {
      printf("Sorry, this program requires GL_ARB_vertex_program");
      exit(1);
   }

   if (!glutExtensionSupported("GL_ARB_fragment_program")) {
      printf("Sorry, this program requires GL_ARB_fragment_program");
      exit(1);
   }
   	
   glGenProgramsARB(1, &prognum);
   glGenProgramsARB(1, &fprognum);

   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                        strlen(prog), (const GLubyte *) prog);

   assert(glIsProgramARB(prognum));
   errno = glGetError();
   printf("glGetError = %d\n", errno);
   if (errno != GL_NO_ERROR)
   {
      GLint errorpos;

      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
      printf("errorpos: %d\n", errorpos);
      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
   }

   glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fprognum);
   glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                        strlen(fprog), (const GLubyte *) fprog);
   errno = glGetError();
   printf("glGetError = %d\n", errno);
   if (errno != GL_NO_ERROR)
   {
      GLint errorpos;

      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
      printf("errorpos: %d\n", errorpos);
      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
   }

   glEnable(GL_VERTEX_PROGRAM_ARB);
   glEnable(GL_FRAGMENT_PROGRAM_ARB);
   glEnable(GL_DEPTH_TEST);
   glClearColor(0.3, 0.3, 0.3, 1);
}
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_ARBVertexProgram_glIsProgramARB(JNIEnv *__env, jclass clazz, jint program) {
    glIsProgramARBPROC glIsProgramARB = (glIsProgramARBPROC)tlsGetFunction(1394);
    UNUSED_PARAM(clazz)
    return (jboolean)glIsProgramARB(program);
}