Help - my pixel-perfect quads are blurry

Blitz3D Forums/Blitz3D Beginners Area/Help - my pixel-perfect quads are blurry

My add_quad() function should draw a section of my image similarly to how DrawImageRect() works. It seems that the quad shows up occupying the correct pixels on the screen, but the image is blurry. My UV math (+.5 to all) is pretty much guesswork, but no amount of experimentation has produced a clear image.

function add_quad(x, y, image_orig_x, image_orig_y, image_width, image_height)
	x1 = x
	y1 = y
	x2 = x + image_width
	y2 = y + image_height
	u1# = image_orig_x
	v1# = image_orig_y
	u2# = image_orig_x+image_width
	v2# = image_orig_y+image_height
	vertex_0 = addvertex(surface, x1, y1, 0, u1, v1)
	vertex_1 = addvertex(surface, x2, y1, 0, u2, v1)
	vertex_2 = addvertex(surface, x2, y2, 0, u2, v2)
	vertex_3 = addvertex(surface, x1, y2, 0, u1, v2)
	addtriangle(surface, vertex_0, vertex_1, vertex_2)
	addtriangle(surface, vertex_0, vertex_2, vertex_3)
end function

Graphics3D 640, 480, 32, 0
SetBuffer Backbuffer()

; create a camera and move it back so that (0,0,0) will be centered in the top left pixel and (graphicswidth, graphicsheight, 0) will be centered in the bottom right pixel
camera = createcamera()
scaleentity(camera, 1, -1, 1)														; 0,0 is the top-left corner, not the bottom right!
camera_zoom# = 1																				; camerazoom defaults to 1
moveentity(camera, .5+graphicswidth()/2, .5+graphicsheight()/2, -camera_zoom*(graphicswidth()/2))

; load our texture and scale it so that UV co-ords are 1 unit = 1 pixel
texture = loadtexture("media\textures\sample_sprites.bmp")
scaletexture(texture, 640, 640)	; the image is 640x640 (texturewidth and textureheight strangely return 1024!)

; create our entity for placing quads on
host_entity = createmesh()
entityfx(host_entity, 1)						; 1 = fullbright
entitytexture(host_entity, texture)
global surface = createsurface(host_entity)

; the image i want to display from my BMP starts at 32,0 and is 32x64
image_orig_x = 32
image_orig_y = 0
image_width = 32
image_height = 64

; for fun, draw it with its top-left corner at 100,100
x = 100
y = 100

; show me the money
add_quad(x, y, image_orig_x, image_orig_y, image_width, image_height)
renderworld
flip
waitkey
end


Any help is greatly appreciated!

I'm not sure if this is the right solution, but have you tried ClearTextureFilters to remove mipmapping?

http://www.blitzbasic.com/b3ddocs/command.php?name=ClearTextureFilters&ref=3d_a-z

Scaling of non-power-of-2 textures often results in blurry images. Most GPU cards have to store and work with power-of-2 image (128x128, 256x256, 256x64, 128x512). Anything larger than one size uses the next size up, so 640x640 needs a 1024x1024 texture to fit it.

I've not looked closely at your code but try a 256x256 bmp first and see what that's like.

The pizza trophy goes to Shifty Geezer! That fixed it, thanks!

Removing mipmapping reduced the blur by a considerable amount, but there was still a tiny bit. Using a 256x256 source image removed the blur completely, even with mipmapping still enabled. Now my sprites are as crisp as the day they were drawn in mspaint.exe!

Now I understand the reason for the "; load squared texture" code in http://www.blitzbasic.com/codearcs/codearcs.php?code=773

Thanks to both of you!