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.
Any help is greatly appreciated!
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!