We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › GLGraphics, GLTexture and linear texture filtering
Page Index Toggle Pages: 1
GLGraphics, GLTexture and linear texture filtering (Read 804 times)
GLGraphics, GLTexture and linear texture filtering
Aug 28th, 2008, 9:09pm
 
Hi,

I'm trying to do some pretty simple textured quads in OpenGL using the GLTexture class from GLGraphics, but I'm noticing that when the quad is scaled bigger than the texture, it appears to be using NEAREST for the mag filter and my texture looks all yucky!

I tried using an alternate constructor, first creating a GLTextureParameters object and manually setting the magfilter to LINEAR and passing that to a new GLTexture constructor and then loading the texture after the GLTexture had been created, but I got the same results.

When I print out getTextureMagFilter(), it returns 9728 while GLConstants.LINEAR is 1. Hmmm...

Anyway, as far as I know, the mag filter used when rendering texture mapped polys is based on how the texture was created and not on a GL render state... maybe I'm mistaken on that. Regardless, I'd like to get some nice texture filtering happening with my GLTextures. Any advice? here is a simplified example:

Code:

import processing.opengl.*;
import javax.media.opengl.*;
import codeanticode.glgraphics.*;

GLTexture halo;
PGraphicsOpenGL pgl;
GL gl;
int quadDisplayList;

void setup()
{
size(800,600,OPENGL);
hint(ENABLE_OPENGL_4X_SMOOTH);
smooth();
pgl = (PGraphicsOpenGL)g;
gl = pgl.gl;
halo = new GLTexture(this, "halo.png");
initGL();
}

void draw()
{
float quadScale = (sin(millis() * .001f) + 1) * .5f;
quadScale *= height;

background(0);
pgl.beginGL();

gl.glPushMatrix();
gl.glTranslatef(width/2f, height/2f, 0);
gl.glScalef(quadScale, quadScale, quadScale);
gl.glColor3f(1.0f, 1.0f, 1.0f);
gl.glCallList(quadDisplayList);
gl.glPopMatrix();

pgl.endGL();
}

private void initGL()
{
pgl.beginGL();
quadDisplayList = gl.glGenLists(1);
gl.glNewList(quadDisplayList, GL.GL_COMPILE);
gl.glBegin(GL.GL_POLYGON);
gl.glTexCoord2f(0, 0);

gl.glVertex2f(-.5f, -.5f);
gl.glTexCoord2f(1, 0);

gl.glVertex2f( .5f, -.5f);
gl.glTexCoord2f(1, 1);

gl.glVertex2f( .5f, .5f);
gl.glTexCoord2f(0, 1);

gl.glVertex2f(-.5f, .5f);
gl.glEnd();
gl.glEndList();

gl.glActiveTexture(GL.GL_TEXTURE0);
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glBindTexture(GL.GL_TEXTURE_2D, halo.getTextureID());
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);

pgl.endGL();
}


Alternately, here is a zipped project including the little texture file: http://bit.ly/3guVMN

This is with Processing 0148 and GLGraphics 0.8.2

Thanks.

-Aaron
Re: GLGraphics, GLTexture and linear texture filte
Reply #1 - Aug 29th, 2008, 6:31am
 
Hello Aaron,

You have actually found a limitation of the current version of the library: you cannot specify the texture parameters (magnification filters, etc) when loading it from an image file. This feature will be added in the next version (I'm adding it to the tracker on the sourceforge website right now).

But fortunately there is a workaround to enable linear filtering when loading an image in the current version. The trick is to first initialize the texture empty with the size of the image you will load into it, and passing to the constructor a GLTextureParameter object with the desired filtering modes. And then you load the image with the loadTexture(filename) function:

Code:

void setup()
{
size(800,600,OPENGL);

// You don't need this:
//hint(ENABLE_OPENGL_4X_SMOOTH);
//smooth();

pgl = (PGraphicsOpenGL)g;
gl = pgl.gl;


// Creating texture with linear filtering and the
// size of the image that will be loaded into it:
GLTextureParameters params = new GLTextureParameters();
params.minFilter = GLTexture.LINEAR;
params.magFilter = GLTexture.LINEAR;
halo = new GLTexture(this, 64, 64, params);

// Loading image.
halo.loadTexture("halo.png");

initGL();
}

Page Index Toggle Pages: 1