317 |
321 |
318 if SDL_MustLock(surf) then |
322 if SDL_MustLock(surf) then |
319 SDLTry(SDL_LockSurface(surf) >= 0, true); |
323 SDLTry(SDL_LockSurface(surf) >= 0, true); |
320 |
324 |
321 if not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h)) then |
325 if not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h)) then |
322 begin |
326 begin |
323 tw:= toPowerOf2(Surf^.w); |
327 tw:= toPowerOf2(Surf^.w); |
324 th:= toPowerOf2(Surf^.h); |
328 th:= toPowerOf2(Surf^.h); |
325 |
329 |
326 GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel); |
330 Surface2Tex^.rx:= Surf^.w / tw; |
327 |
331 Surface2Tex^.ry:= Surf^.h / th; |
328 gluScaleImage(mode, Surf^.w, Surf^.h, GL_UNSIGNED_BYTE, |
332 |
329 Surf^.pixels, tw, th, GL_UNSIGNED_BYTE, |
333 GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel); |
330 tmpp); |
334 |
331 |
335 if surf^.format^.BytesPerPixel = 4 then |
332 glTexImage2D(GL_TEXTURE_2D, 0, mode, tw, th, 0, mode, GL_UNSIGNED_BYTE, tmpp); |
336 begin |
333 |
337 fromP4:= Surf^.pixels; |
334 FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
338 toP4:= tmpp; |
335 end else |
339 |
336 glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels); |
340 for y:= 0 to Pred(Surf^.h) do |
|
341 begin |
|
342 for x:= 0 to Pred(Surf^.w) do |
|
343 toP4^[x]:= fromP4^[x]; |
|
344 for x:= Surf^.w to Pred(tw) do |
|
345 toP4^[x]:= 0; |
|
346 toP4:= @(toP4^[tw]); |
|
347 fromP4:= @(fromP4^[Surf^.w]); |
|
348 end; |
|
349 |
|
350 for y:= Surf^.h to Pred(th) do |
|
351 begin |
|
352 for x:= 0 to Pred(tw) do |
|
353 toP4^[x]:= 0; |
|
354 toP4:= @(toP4^[tw]); |
|
355 end; |
|
356 end |
|
357 else |
|
358 begin |
|
359 fromP1:= Surf^.pixels; |
|
360 toP1:= tmpp; |
|
361 |
|
362 for y:= 0 to Pred(Surf^.h) do |
|
363 begin |
|
364 for x:= 0 to Pred(Surf^.w) do |
|
365 begin |
|
366 toP1^[x * 3]:= fromP1^[x * 3]; |
|
367 toP1^[x * 3 + 1]:= fromP1^[x * 3 + 1]; |
|
368 toP1^[x * 3 + 2]:= fromP1^[x * 3 + 2]; |
|
369 end; |
|
370 for x:= Surf^.w to Pred(tw) do |
|
371 begin |
|
372 toP1^[x * 3]:= 0; |
|
373 toP1^[x * 3 + 1]:= 0; |
|
374 toP1^[x * 3 + 2]:= 0; |
|
375 end; |
|
376 toP1:= @(toP1^[tw * 3]); |
|
377 fromP1:= @(fromP1^[Surf^.pitch]); |
|
378 end; |
|
379 |
|
380 for y:= Surf^.h to Pred(th) do |
|
381 begin |
|
382 for x:= 0 to Pred(tw) do |
|
383 begin |
|
384 toP1^[x * 3]:= 0; |
|
385 toP1^[x * 3 + 1]:= 0; |
|
386 toP1^[x * 3 + 2]:= 0; |
|
387 end; |
|
388 toP1:= @(toP1^[tw * 3]); |
|
389 end; |
|
390 end; |
|
391 |
|
392 // gluScaleImage(mode, Surf^.w, Surf^.h, GL_UNSIGNED_BYTE, |
|
393 // Surf^.pixels, tw, th, GL_UNSIGNED_BYTE, |
|
394 // tmpp); |
|
395 |
|
396 glTexImage2D(GL_TEXTURE_2D, 0, mode, tw, th, 0, mode, GL_UNSIGNED_BYTE, tmpp); |
|
397 |
|
398 FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
|
399 end else |
|
400 begin |
|
401 Surface2Tex^.rx:= 1.0; |
|
402 Surface2Tex^.ry:= 1.0; |
|
403 glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels); |
|
404 end; |
337 |
405 |
338 if SDL_MustLock(surf) then |
406 if SDL_MustLock(surf) then |
339 SDL_UnlockSurface(surf); |
407 SDL_UnlockSurface(surf); |
340 |
408 |
341 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
409 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |