Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-04-2011, 06:37 AM   #1 (permalink)
MTR
Registered Member
 
Join Date: Nov 2009
Posts: 3
MTR is on a distinguished road
Question opengl texture filter

Hello!

I'm having a problem with the filtering in textures.
When I scale the image to bigger, the linear filter is not working (looks more nearest than linear).
This is the result I'm having:

(image on the left is ratio 1, so it looks Ok. Image on the right has ration 1.5 and looks too pixeled)

And this is the result I have in PC and Android phones:



Concerning the code of creation of texture, I'm doing the same than everyone else:

Code:
glBindTexture (GL_TEXTURE_2D, idx);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexEnvi (GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Texture is ARGB 8888.

Any idea of why is this happening?

Thank you in advance!
MTR is offline   Reply With Quote
Old 02-04-2011, 08:05 AM   #2 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 7
Bounty Bob is on a distinguished road
Default

You say that it looks more like a nearest filter than linear, but have you set the filters to nearest to see how the results are? Im guessing it will look worse.

Whenever I've needed to display a larger image, I've always used a larger source image for better quality, unless it's only going to be seen at that larger size briefly.

*edit* Are you doing this at the glGenTextures point of the code?
Bounty Bob is offline   Reply With Quote
Old 02-04-2011, 10:32 AM   #3 (permalink)
MTR
Registered Member
 
Join Date: Nov 2009
Posts: 3
MTR is on a distinguished road
Default

Thanks for your answer,

I check GL_NEAREST and looks the same than GL_LINEAR.

For special effects, I need to change the size of displayed images.
I have the same problem when using a larger source image and displaying it smaller.

The fact is that I haven't see this problem in other games.

This is the whole code when creating textures:

Code:
glGenTextures(1, &idx);

glBindTexture (GL_TEXTURE_2D, idx);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvi (GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)w,(GLsizei)h, 0, GL_RGBA, GL_UNSIGNED_BYTE, dataChar);
MTR is offline   Reply With Quote
Old 02-04-2011, 01:48 PM   #4 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 234
warmi is on a distinguished road
Default

Quote:
Originally Posted by MTR View Post
Hello!

I'm having a problem with the filtering in textures.
When I scale the image to bigger, the linear filter is not working (looks more nearest than linear).
This is the result I'm having:

(image on the left is ratio 1, so it looks Ok. Image on the right has ration 1.5 and looks too pixeled)

And this is the result I have in PC and Android phones:



Concerning the code of creation of texture, I'm doing the same than everyone else:

Code:
glBindTexture (GL_TEXTURE_2D, idx);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexEnvi (GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Texture is ARGB 8888.

Any idea of why is this happening?

Thank you in advance!
Are your textures power of 2 ?
warmi is offline   Reply With Quote
Old 02-04-2011, 04:40 PM   #5 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 7
Bounty Bob is on a distinguished road
Default

Quote:
Originally Posted by MTR View Post
Thanks for your answer,

I check GL_NEAREST and looks the same than GL_LINEAR.

For special effects, I need to change the size of displayed images.
I have the same problem when using a larger source image and displaying it smaller.

The fact is that I haven't see this problem in other games.

This is the whole code when creating textures:

Code:
glGenTextures(1, &idx);

glBindTexture (GL_TEXTURE_2D, idx);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvi (GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)w,(GLsizei)h, 0, GL_RGBA, GL_UNSIGNED_BYTE, dataChar);
You have the same as I do for texture generation, except I don't have the glTexEnvi. Are you using this later for your effects? Maybe try taking it out and seeing if scaling is affected.

How are you drawing the objects?

And as above, what are the dimensions of your textures?
Bounty Bob is offline   Reply With Quote
Old 02-09-2011, 04:57 AM   #6 (permalink)
MTR
Registered Member
 
Join Date: Nov 2009
Posts: 3
MTR is on a distinguished road
Default Solution

Thanks for your answer,

The problem was that I was repeating glTexParameteri when rendering the triangle fan.
Looks like calling glTexParameteri after creating textures disables the LINEAR filter of all textures.

Solution:
Code:
uploadTexture ()
{
glGenTextures(1, &idx);

glBindTexture (GL_TEXTURE_2D, idx);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvi (GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)w,(GLsizei)h, 0, GL_RGBA, GL_UNSIGNED_BYTE, dataChar);
}

rendering()
{
[...]
//	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
[...]
}
MTR is offline   Reply With Quote
Reply

Bookmarks

Tags
filter, gl_linear, opengl, ratio, texture

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 418
10 members and 408 guests
7twenty7, chemistry, ChrisYates, gmarro, hussain1982, Retouchable, skrew88, SLIC, walex, xzoonxoom
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,921
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:10 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0