Exemplo n.º 1
0
Arquivo: g_render.c Projeto: aosm/X11
void __glXDisp_ConvolutionParameteri(GLbyte *pc)
{
	glConvolutionParameteri( 
		*(GLenum   *)(pc + 0),
		*(GLenum   *)(pc + 4),
		*(GLint    *)(pc + 8)
	);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBImaging_nglConvolutionParameteri(JNIEnv *env, jclass clazz, jint target, jint pname, jint params, jlong function_pointer) {
    glConvolutionParameteriPROC glConvolutionParameteri = (glConvolutionParameteriPROC)((intptr_t)function_pointer);
    glConvolutionParameteri(target, pname, params);
}
Exemplo n.º 3
0
static void Init( int argc, char *argv[] )
{
   GLboolean convolve = GL_FALSE;
   GLboolean fullscreen = GL_FALSE;
   int i;

   for (i = 1; i < argc; i++) {
      if (strcmp(argv[i], "-info")==0) {
         printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
         printf("GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
         printf("GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
         printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
      }
      else if (strcmp(argv[i], "-c")==0) {
         convolve = GL_TRUE;
      }
      else if (strcmp(argv[i], "-f")==0) {
         fullscreen = GL_TRUE;
      }
   }

   if (fullscreen)
      glutFullScreen();

   /* Cylinder object */
   {
      static GLfloat height = 100.0;
      static GLfloat radius = 40.0;
      static GLint slices = 24;  /* pie slices around Z axis */
      static GLint stacks = 10;  /* subdivisions along length of cylinder */
      static GLint rings = 4;    /* rings in the end disks */
      GLUquadricObj *q = gluNewQuadric();
      assert(q);
      gluQuadricTexture(q, GL_TRUE);

      CylinderObj = glGenLists(1);
      glNewList(CylinderObj, GL_COMPILE);

      glPushMatrix();
      glTranslatef(0.0, 0.0, -0.5 * height);

      glMatrixMode(GL_TEXTURE);
      glLoadIdentity();
      /*glScalef(8.0, 4.0, 2.0);*/
      glMatrixMode(GL_MODELVIEW);

      /* cylinder */
      gluQuadricNormals(q, GL_SMOOTH);
      gluQuadricTexture(q, GL_TRUE);
      gluCylinder(q, radius, radius, height, slices, stacks);

      /* end cap */
      glMatrixMode(GL_TEXTURE);
      glLoadIdentity();
      glScalef(3.0, 3.0, 1.0);
      glMatrixMode(GL_MODELVIEW);

      glTranslatef(0.0, 0.0, height);
      gluDisk(q, 0.0, radius, slices, rings);

      /* other end cap */
      glTranslatef(0.0, 0.0, -height);
      gluQuadricOrientation(q, GLU_INSIDE);
      gluDisk(q, 0.0, radius, slices, rings);

      glPopMatrix();

      glMatrixMode(GL_TEXTURE);
      glLoadIdentity();
      glMatrixMode(GL_MODELVIEW);

      glEndList();
      gluDeleteQuadric(q);
   }

   /* Teapot */
   {
      TeapotObj = glGenLists(1);
      glNewList(TeapotObj, GL_COMPILE);

      glFrontFace(GL_CW);
      glutSolidTeapot(40.0);
      glFrontFace(GL_CCW);

      glEndList();
   }

   /* show cylinder by default */
   Object = CylinderObj;


   /* lighting */
   glEnable(GL_LIGHTING);
   {
      GLfloat pos[4] = { 3, 3, 3, 1 };
      glLightfv(GL_LIGHT0, GL_AMBIENT, Black);
      glLightfv(GL_LIGHT0, GL_DIFFUSE, White);
      glLightfv(GL_LIGHT0, GL_SPECULAR, White);
      glLightfv(GL_LIGHT0, GL_POSITION, pos);
      glEnable(GL_LIGHT0);
      glMaterialfv(GL_FRONT, GL_AMBIENT, Black);
      glMaterialf(GL_FRONT, GL_SHININESS, Shininess);
      glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
   }

   /* Base texture */
   glGenTextures(1, &BaseTexture);
   glBindTexture(GL_TEXTURE_2D, BaseTexture);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   if (!LoadRGBMipmaps(BASE_TEXTURE_FILE, GL_RGB)) {
      printf("Error: couldn't load texture image file %s\n", BASE_TEXTURE_FILE);
      exit(1);
   }

   /* Specular texture */
   glGenTextures(1, &SpecularTexture);
   glBindTexture(GL_TEXTURE_2D, SpecularTexture);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
   if (convolve) {
      /* use convolution to blur the texture to simulate a dull finish
       * on the object.
       */
      GLubyte *img;
      GLenum format;
      GLint w, h;
      GLfloat filter[FILTER_SIZE][FILTER_SIZE][4];

      for (h = 0; h < FILTER_SIZE; h++) {
         for (w = 0; w < FILTER_SIZE; w++) {
            const GLfloat k = 1.0 / (FILTER_SIZE * FILTER_SIZE);
            filter[h][w][0] = k;
            filter[h][w][1] = k;
            filter[h][w][2] = k;
            filter[h][w][3] = k;
         }
      }

      glEnable(GL_CONVOLUTION_2D);
      glConvolutionParameteri(GL_CONVOLUTION_2D,
                              GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
      glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_RGBA,
                            FILTER_SIZE, FILTER_SIZE,
                            GL_RGBA, GL_FLOAT, filter);

      img = LoadRGBImage(SPECULAR_TEXTURE_FILE, &w, &h, &format);
      if (!img) {
         printf("Error: couldn't load texture image file %s\n",
                SPECULAR_TEXTURE_FILE);
         exit(1);
      }

      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0,
                   format, GL_UNSIGNED_BYTE, img);
      free(img);
   }
   else {
      /* regular path */
      if (!LoadRGBMipmaps(SPECULAR_TEXTURE_FILE, GL_RGB)) {
         printf("Error: couldn't load texture image file %s\n",
                SPECULAR_TEXTURE_FILE);
         exit(1);
      }
   }

   /* misc */
   glEnable(GL_CULL_FACE);
   glEnable(GL_TEXTURE_2D);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_NORMALIZE);

   glPolygonOffset( -1, -1 );
}
Exemplo n.º 4
0
void GLFont::uploadStringTexture(const char* string,GLsizei stringWidth,GLsizei textureWidth) const
	{
	/* Calculate the proper texture image dimensions: */
	GLsizei imageWidth,imageHeight;
	int x,baseLineRow;
	if(antialiasing)
		{
		imageWidth=stringWidth;
		imageHeight=fontHeight;
		baseLineRow=baseLine;
		x=maxLeftLap+1;
		}
	else
		{
		imageWidth=stringWidth;
		imageHeight=fontHeight;
		baseLineRow=baseLine;
		x=maxLeftLap+1;
		}
	
	/* Create a luminance-only texture image of appropriate size: */
	GLubyte* image=new GLubyte[imageWidth*imageHeight];
	memset(image,255,imageWidth*imageHeight);
	
	if(string!=0)
		{
		/* Copy all characters into the texture image: */
		for(const char* cPtr=string;*cPtr!=0;++cPtr)
			{
			int charIndex=int(*cPtr)-firstCharacter;
			if(charIndex>=0&&charIndex<numCharacters)
				{
				const CharInfo* ciPtr=&characters[charIndex];
				const unsigned char* rasterLine=&rasterLines[ciPtr->rasterLineOffset];
				const unsigned char* span=&spans[ciPtr->spanOffset];
				
				/* Copy all raster lines: */
				for(int y=baseLineRow-ciPtr->descent;y<baseLineRow+ciPtr->ascent;++y,++rasterLine)
					{
					/* Copy all spans in this line: */
					GLubyte* texPtr=&image[imageWidth*y+x+ciPtr->glyphOffset];
					int numSpans=int(*rasterLine);
					for(int i=0;i<numSpans;++i,++span)
						{
						texPtr+=int((*span)>>3);
						int numPixels=int((*span)&0x07);
						for(int j=0;j<numPixels;++j,++texPtr)
							*texPtr=GLubyte(0);
						}
					}
				
				x+=ciPtr->width;
				}
			}
		}
	
	/* Upload the created texture image: */
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glPixelStorei(GL_UNPACK_SKIP_PIXELS,0);
	glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
	glPixelStorei(GL_UNPACK_SKIP_ROWS,0);
	glPixelStorei(GL_UNPACK_ALIGNMENT,1);
	glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE,textureWidth,textureHeight,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,0);
	if(antialiasing)
		{
		static GLfloat kernel[3]={0.25,0.5,0.25};
		// static GLfloat kernel[5]={0.125,0.2,0.35,0.2,0.125};
		glConvolutionParameteri(GL_SEPARABLE_2D,GL_CONVOLUTION_BORDER_MODE,GL_REPLICATE_BORDER);
		glSeparableFilter2D(GL_SEPARABLE_2D,GL_LUMINANCE,3,3,GL_LUMINANCE,GL_FLOAT,kernel,kernel);
		glEnable(GL_SEPARABLE_2D);
		glTexSubImage2D(GL_TEXTURE_2D,0,0,0,imageWidth,imageHeight,GL_LUMINANCE,GL_UNSIGNED_BYTE,image);
		glDisable(GL_SEPARABLE_2D);
		}
	else
		glTexSubImage2D(GL_TEXTURE_2D,0,0,0,imageWidth,imageHeight,GL_LUMINANCE,GL_UNSIGNED_BYTE,image);
	
	/* Clean up and return: */
	delete[] image;
	}