Problem with Polyvector

Previous topic - Next topic

Kyo

Hi.
I have a problem with the command Polyvector.

when join two images (tile system), it creates a black line in the middle!

I use images size 200x200 24-bit PNG.

I thought it was the ClearScreen with rgb (0,0,0) but I changed the value to rgb (255,0,0).

Then I thought that I had to use the command Polynewstrip (instead of individual Polystrip), but the error remains.



Can anyone help me?  :giveup:

dreamerman

Little to small image, but from these diagonal lines I would say that maybe texture coords are little wrong.. on the other hand always use 'SMOOTHSHADING FALSE' to eliminate artifacts which may arise from stretching and rotations..
Check my source code editor for GLBasic - link Update: 20.04.2020

Kyo

Thank's for reply ...  :booze:
The problem is the black line in the middle (not diagonal).

I tried with the smoothading false but the problem remains ....  :rant:

bigsofty

Could you post some code that illustrates the problem?
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

mentalthink

Are you moving the images ?¿, and it's very slow?¿, I have the same problem and I solved put a bit more of speed, ot simply put a polyvector each the other and then adjust the UV coordinates... It's extrange , in my Black Sun video, you can see this problem too.

Kyo

soon, I enclose the code.

Kyo

Ok this is an example!

Use left/right on keyboard to move the 2nd rectangle (texture).
In position 0 you see a thin black line, that makes lose the sense of continuity.



Kyo

Use this example:

with A and S move the rectangles together and it shows the problem

bigsofty

#8
I changed your code a little to avoid a couple of texel rendering problems.

1) Changed the texture clamping behaviour of the polyvector rendering. I think it defaults to GL_CLAMP, which needs a 1 pixel border to work(doesn't work at all after GL 3.1) to GL_CLAMP_TO_EDGE.

2) Changed your final rendering co-ordinates to integer to avoid sub-pixel rendering.

3) Took 1 off the width and heigh of your sprite for your texture co-ordinates, sx=0 - spriteWidth-1 for example.

Look for the // Changed \\ Remarks

Code (glbasic) Select

// Changed \\
IMPORT "C" void __stdcall glTexParameteri(unsigned int flag, unsigned int flag, unsigned int flag);
GLOBAL GL_CLAMP_TO_EDGE%                                   = 0x812F
GLOBAL GL_TEXTURE_2D%                                      = 0x0DE1
GLOBAL GL_TEXTURE_WRAP_S%                                  = 0x2802
GLOBAL GL_TEXTURE_WRAP_T%                                  = 0x2803


SETCURRENTDIR("Media") // go to media files

//SETSCREEN 700,440,FALSE
SETSCREEN 1280,800,TRUE

SMOOTHSHADING TRUE

LIMITFPS 30



////////////////////////
// array per characters
TYPE tLevel
id_sprite%
pos_x
ENDTYPE

GLOBAL Level[] AS tLevel
DIM Level[1][3]


initZ(1)

Load_Stage( "1")


CLEARSCREEN RGB(255,0,0)

WHILE TRUE
Draw_Stage()
SHOWSCREEN
WEND
END



FUNCTION Load_Stage:  nome$

Level[0][1].id_sprite% =  1
Level[0][1].pos_x =0
LOADSPRITE  "1.png",  1

Level[0][2].id_sprite% =  2
Level[0][2].pos_x = 198
LOADSPRITE  "1.png",  2

ENDFUNCTION



GLOBAL move_rect

FUNCTION Draw_Stage:


IF KEY(205) THEN move_rect = move_rect + 1
IF KEY(203) THEN move_rect = move_rect - 1

FOR x = 1 TO 2
x_pos = Level[0][x].pos_x
id_sx% = Level[0][x].id_sprite%
IF x = 2 THEN x_pos = x_pos + move_rect
z_drawstage(id_sx,x_pos,-50)
NEXT

PRINT move_rect ,0,0

ENDFUNCTION // DRAW_STAGE



FUNCTION z_drawstage: num%,x%,y%,xzoom = 0, yzoom = 0, adv_x = 0, Scale# = 1, color=0xFFFFFF
LOCAL sx%,sy%,x1%,y1%,x2%,y2%// Changed \\

GETSPRITESIZE num,sx,sy

IF xzoom <> 0 THEN xzoom = x_zoom + xzoom
IF yzoom <> 0 THEN yzoom = y_zoom + yzoom

IF xzoom <> 0 THEN x = x - adv_x


IF xzoom = 0 THEN xzoom = x_zoom
IF yzoom = 0 THEN yzoom = y_zoom



x1=(x_offset+(x*xzoom)) * Scale#
x2=(sx*xzoom) * Scale#
y1=(y_offset+(y*yzoom)) * Scale#
y2=(sy*yzoom) * Scale#


STARTPOLY num
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);// Changed \\
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);// Changed \\
POLYVECTOR x1,y1,0,0,color
POLYVECTOR x1,y1+y2,0,sy-1,color// Changed \\
POLYVECTOR x1+x2,y1+y2,sx-1,sy-1,color// Changed \\
POLYVECTOR x1+x2,y1,sx-1,0,color// Changed \\
ENDPOLY


ENDFUNCTION






GLOBAL x_offset,y_offset //offset to add to X&Y to display correctly
GLOBAL x_res,y_res //X&Y real screen size
GLOBAL x_zoom,y_zoom //zoom to scale sprites and so
GLOBAL x_orig=700,y_orig=440 //the screen size our app is designed for
GLOBAL single_sheet=0 //1 IF all sprites in a single sheet
GLOBAL new_x_resize = 1
GLOBAL keep

FUNCTION initZ: keep_ratio=0
LOCAL z


IF keep_ratio= 1 THEN keep = keep_ratio

GETSCREENSIZE x_res,y_res

x_zoom=x_res/x_orig
y_zoom=y_res/y_orig

//DEBUG "x_zoom : " + x_zoom + "  y_zoom : " + y_zoom



IF keep_ratio<>0
z=MIN(x_zoom,y_zoom)
x_zoom=z
    y_zoom=z
x_offset=(x_res-(x_orig*x_zoom))/2
y_offset=(y_res-(y_orig*y_zoom))/2
IF x_offset<1 THEN x_offset=0
IF y_offset<1 THEN y_offset=0

ENDIF

init_SC()

ENDFUNCTION



INLINE
#define OGL ::
typedef float           GLfloat;
ENDINLINE

INLINE
} extern "C" { void __stdcall glLineWidth( GLfloat width );; }; namespace __GLBASIC__ {
ENDINLINE
FUNCTION glLineWidth: width
INLINE
OGL glLineWidth(width);
ENDINLINE
ENDFUNCTION


INLINE
} //  + + + A T T E N T I O N + + +
// int __a__ needs to be a n^2 value.
// Higher values give better precision
// but larger lookup tables as well!

const unsigned int __a__ = 131072 ;
const DGInt __b__ = (360.0 / __a__) ;
const unsigned int __c__ = (__a__ - 1) ;
DGInt _sin_tbl_[__c__] ;
DGInt _cos_tbl_[__c__] ;
const DGInt __d__ = (1 / __b__);
namespace __GLBASIC__ {
ENDINLINE

FUNCTION init_SC:
INLINE
for(int i=0; i < __c__; ++i)
{
_sin_tbl_[i] = SIN( i * __b__ ) ;
_cos_tbl_[i] = COS( i * __b__ ) ;
}
ENDINLINE
ENDFUNCTION // INIT_SIN_COS_TABLES

// ------------------------------------------------------------- //
// ---  TCOS  ---
// ------------------------------------------------------------- //
FUNCTION tCOS: x // in degrees
INLINE
return _cos_tbl_[ (int)(x * __d__) & __c__ ] ;
ENDINLINE
ENDFUNCTION // TCOS



// ------------------------------------------------------------- //
// ---  TSIN  ---
// ------------------------------------------------------------- //
FUNCTION tSIN: x  // in degrees
INLINE
return _sin_tbl_[ (int)(x * __d__) & __c__ ] ;
ENDINLINE
ENDFUNCTION // TSIN
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Schranz0r

Textures should have(^2, depends to the graphicscard):

16x16, 32x32, 64x64,128x128,256x256,512x512,...
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kyo

 Schranz0r you're right, the texture must be ^2  :booze:

but the code of bigsofty work very fine!  :good:

thanks for the help!  :nw:

Wampus

#11
This looks fixed but I wanted to add an additional comment. In bigosfty's example there is an alternative to taking 1 pixel off the width and height off the texture co-ordinates. Extrude the original tile/sprite edges by 1 to 2 pixels instead, but have the texture co-ordinates set to the original tile/sprite size. So, if a tile/sprite is 64x64 large, then the new tile/sprite would be 66x66 large with the top left corner of the texture starting at 1,1 and ending at 65,65. Does that make sense? Doing this manually in a paint program is a bit of a pain but you could automate the process or use something like Texture Packer. Incidentally, doing this will also get rid of the edge artifacts even without having to modify the default OpenGL texture parameters in GLBasic.

EDIT: I added an attachment example. Its the same code and image from tile.rar although I've changed a couple of things:-

1) I extruded the edges of 1.png by 2 pixels each edge so that the original texture of 200x200 is now 204x204. If you look in the Media folder you should find the original 1.png sprite and the new one called 2.png

2) To reflect the extruded edges the drawing code is now...

      sx = 200
      sy = 200

      ...

      POLYVECTOR x1,y1,2,2,color
      POLYVECTOR x1,y1+y2,2,sy+2,color
      POLYVECTOR x1+x2,y1+y2,sx+2,sy+2,color
      POLYVECTOR x1+x2,y1,sx+2,2,color

Instead of

      GETSPRITESIZE num, sx, sy

      ...

      POLYVECTOR x1,y1,0,0,color
      POLYVECTOR x1,y1+y2,0,sy,color
      POLYVECTOR x1+x2,y1+y2,sx,sy,color
      POLYVECTOR x1+x2,y1,sx,0,color

Obviously it wouldn't be right to hard code the texture coordinates this way for each sprite. For the purposes of the example its ok though.

bigsofty

Both methods are perfectly valid.

Just to be clear though, the reason I removed 1 from the width and height of the sprite is because POLYVECTOR() texture coords start from and include 0. Lets say GETSPRITESIZE() gives you a sprite of 64x64, the texture coords would range from 0 - 63 x 0 - 63.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Kitty Hello

Use coords 0.5 and 62.5 instead of 0 and 63. 64 is definitely too far off that's pixel 0 again!

Kyo

Thanks to all again, for the help!

Great Comunity :booze: :good: :nw: