FAQSGL programming related
■ | Advance
FAQ / SGL programming related

Sprites / polygons



I want to pause the drawing of a sprite.

Q)
I want to temporarily interrupt only the drawing of sprites.

A)
There is a PauseFlag in the SGL system variable. When this is turned ON, the transfer from the sprite buffer performed by the SGL system in V-Blank to VDP1 is not performed. This allows for the effect of not displaying sprites, for example during a pause.

Use extern declarations for SGL system variables, not just PauseFlag.


I want to change the ratio of sprite color calculation.

Q)
How can I set the color calculation ratio of the sprite screen (for example, translucent)?

A)
SlColRate () is provided as a function. Also, a macro that uses this function

slColRate *

(example)
slColRateNBG0

there is.
This is described in SL_DEF.H. You can use this function or these macros to set the percentage of sprite color operations.


I want to give priority to the display of sprites.

Q)
When displaying 2D sprites with slPutSprite, I want to give priority to two sprites at the same coordinates, but if I change the coordinates in the direction of the camera position, the display position will be different when converted to transparent coordinates. ..

Is there a way to give priority arbitrarily when displaying at the same coordinates using slPutSprite?

A)
In SGL, if you try to display at the same Z coordinate, the one registered later (sprite or polygon) in the Z buffer has a higher priority (that is, the front).
For polygons, you can avoid it to some extent by selecting a representative value of Z, but since sprites do not have the concept of depth, the order in which the functions are executed is the only way to change it.
If there is room in the processing and the priority you want to attach is decided, I think that the most effective means is to calculate the position and display scale on the user side and have slDispSprite () adjust the Z position.


I want to change the display position to another location with the sprite drawing function.

Q)
In slPutSprite and slDispSprite, the center point of the data is treated as the reference point. Is it possible to change this to the upper left or below the center?

A)
With the slPutSprite or slDispSprite function, you can basically set the drawing reference point to anything other than the center.
If you want to do something like this, you can specify it using slSetSprite or slDispSprite4P.


Polygons disappear or noise like lines runs on the screen.

Q)
When the polygon approaches the front in SGL, it disappears due to clipping or noise like a line runs on the screen.

A)

  1. When setting polygons, change the second argument (sort setting) of the ATTR structure.
    By default in SOFTIMAGE Export, the sort setting is SORT_CEN, but if this is set to SORT_MAX, it will be the farthest from the reference point of Z sorting, so the position where polygons are missing will be slightly closer.

  2. Increase the argument given to slZdspLevel.
    The slZdspLevel can be a value from 0 to 7. The larger the value, the closer it is displayed.

  3. Reduce the coordinate values that make up the polygon.
    Inside SGL, clipping is applied to the Z-axis with respect to the coordinates of the polygon, but clipping processing is not performed for the XY component, so overflow or underflow occurs in the frame buffer space, and the screen is displayed. Noise may run. This is a process to avoid this.

  4. Change the number of polygons in the model between the front and the back.
    Specifically, it means that the polygon that comes to the front is divided.
    Of course, if a texture is pasted, the texture is also divided, so it is necessary to prepare multiple model patterns and textures for one model on the application side.

supplement
Utilize the near clipping function of SGL Ver 3.0 or later.
However, in this case as well, the techniques from 1 to 4 above can be used as they are.


I feel that the display of sprites and polygons is delayed by one tempo.

Q)
When displaying a sprite on SGL, I knew that the sprite (slDispSprite, slPutPolygon, etc.) that executed the display function in that frame would be displayed in the next frame, but it doesn't work.

in short,

slDispSprite (...);
slSynch ();
OtherProc (); ← It should be displayed at this point, but slSynch ();
OtherProc (); ← It actually looks like it is displayed here

The phenomenon that occurs. How are you?

A)
VDP1 is delayed by one processing frame compared to VDP2, so as you pointed out, it will not be displayed unless slSynch is executed twice.

This is because VDP1 has a double frame buffer, so what the user writes to the command buffer is written to the back frame buffer at the next frame.
Therefore, the contents of the back buffer are displayed in the next frame after writing to the command buffer.
in short,

slDispSprite (...);
slSynch (); ← At this time, the contents of the command are reflected in the back frame buffer.
OtherProc ();
slSynch (); ← At this point, the contents of the back frame buffer are overlaid with the VDP2 video.
OtherProc (); ← Displayed here.

It will be the flow.


I want to define a new texture by changing the system variable FormTbl.

Q)
I want to load model data and texture data into the game as it progresses. Therefore, I want to rewrite the table of the TEXTURE structure, but I don't know the specific method.

A)
<About drawing the system variable FormTbl and polygons and sprites> When using the drawing request function for polygons and sprites, FormTbl is referenced in the function, but in these functions the command is issued by looking at the contents of the cache. increase.

In other words, the contents of FormTbl cannot be changed within 1 unit processing under normal usage.

There are two possible ways to avoid this:

Method 1: Change the address itself indicated by FormTbl
[Procedure.1] Purge the cache on the slave side.
By purging the cache from the slave side and reflecting the update result before resetting FormTbl, the above program can be operated. Specifically, first make sure that the slave processing is finished. To know the activity status of the slave

ComRdPtr, ComWrPtr

Refer to the contents of these two system variables.
When these two system variables are the same as the data referenced when the slave is processing slPutPolygon etc., the slave is not processing SGL.

However, since the slave CPU is always looking at the cache area, the address to be compared must also be in the cache. That is, system variables

ComWrPtr, ComRdPtr

Instead of looking at

ComWrPtr + 0x20000000
ComRdPtr + 0x20000000

Must see.
These registers point to the addresses where the slave is reading and writing commands, and if these values are the same, the slave can be considered to be in a standby state, so first of all, these two registers Compare the values and wait for the same value.
Next, execute slCashePurge from the slave side to purge the cache. Use slSlaveFunction for this.

[Procedure.2] Purge the cache on the slave side.

Method 2: Modify FormTbl.
Change the contents of the structure indicated by FormTbl.
This method is to change the original data without touching FormTbl at all.

for example,
slInitStstem (TV_320x224, TEXTURE_TBL, 1)
If FormTbl is specified as in, later changes,

TEXTURE_TBL [i] .Hsize = ....
TEXTURE_TBL [i] .Vsize = ....
TEXTURE_TBL [i] .CGadr = ....
TEXTURE_TBL [i] .HVsize = ....

It is a way to change it like this. If you use this method, you don't need to know the state of the slave, but you need to have enough space for the TEXTURE structure array (that is, MAX of the display sprite) when you first pass it to slInitSystem. I have.

* Depending on the character data transfer timing, the displayed character may be garbled. This is probably because when VDP1 transfers the character data to the framebuffer, the VRAM data is being rewritten by the character data transfer (even though it is still in use).

To avoid such a situation, transfer character data or lookup table data glow data in the function specified by slIntFunction, or wait for the drawing of VDP1 to finish before transferring.

To know the end of drawing of VDP1, you can judge by looking at the transfer end status register of VDP1 (see VDP1 User's Manual 4.6 Transfer end status register).


What is the Z position given to the sprite drawing function?

Q)
Q8) What is the Z position used in the sprite drawing function?

A)
A8) The Z position is only used to determine the priority between sprites. There is no change in scale when the Z position is changed.

I want to save the contents of the framebuffer.

Q)
Q9) I want to use SGL to overwrite the sprite (without erasing) on the framebuffer of VDP1 while keeping the previous contents. What kind of setting should I make?

A)
A9) There is a function called slGetFrameData, which may be a little different from what you want. This function saves the data in the framebuffer and can be used in the next frame. However, there is a limit to the memory and the contents of VDP2 are not reflected, so when using it, you should think that it is almost impossible to use it for the full screen.

Can I use the UseLight option for palettes and color lookups?

Q)
Q10) In SGL, if the light source calculation process is specified for a polygon with a specified texture (which was simply called a texture in the manual), will the result be reflected correctly when it is actually drawn?

A)
A10) Basically, the USE_LIGHT option works only for SGL polygons when the texture is written in RGB mode. This is a VDP1 specification, so it's not limited to SGL. However, even in the palette format, there are ways to achieve this, such as by directly manipulating the palette.

Tell me how to use the slSetSprite function.

Q)
Q11) I'm not sure how to use the slSetSprite function.

A)
A11) slSetSprite is a function for directly manipulating the data in the VDP1 command table, and its details match the VDP1 command. If you want to know how you are using it, and if you are using Cinepak, please refer to the Cinepak sample program. Also, see the attached sample program.

I want to give priority to scrolling for each sprite.

Q)
I don't know how to prioritize sprites in the SGL environment.
Where (how) do you set this to be SPR0 and this to be SPR1 for each sprite when you do something like slPriority (scnSPR0,7)?
Is it possible to display sprites across the BG screen using SGL?

A)
--- About sprite types and priorities --- When sprite data is passed to VDP2, it is recognized as 8 types of high resolution and low resolution data depending on the type. Depending on each type, VDP2 sets scroll and sprite priorities. Sprites and scrolls can be displayed in order by setting which scroll and what priority the eight types have.

In addition to sprite and scroll priorities, you can also set shadows and color calculations between them.
This type of sprite is called a sprite type in VDP2.

reference
VDP1 User's Manual 6.4 CMDCOLR Color Bank
VDP2 User's Manual 9.1 Sprite Data

The sprite type can be given to each sprite unit when VDP1 is set. In SGL, this setting can be done when setting the color palette.
Here is an example.

First, select the sprite type you want to use.
The default is sprite type 3. To change it, call the slSpriteType () function with the sprite type as an argument.

next

#define PrioNo0 (0 << 12)
#define PrioNo1 (1 << 12)
#define PrioNo2 (2 << 12)
#define PrioNo3 (3 << 12)
#define PrioNo4 (4 << 12)
#define PrioNo5 (5 << 12)
#define PrioNo6 (6 << 12)
#define PrioNo7 (7 << 12)

Is defined.

・ For polygons

ATTRIBUTE (Single_Plane, SORT_CEN, tex1, PrioNo4 | 0x0010 , No_Gouraud, ..
Here, the priority number of the polygon is set to 4. In other words, the priority number 0 to 7 can be set by taking OR for the palette number.

・ For slPutSprite and slDispSprite *

SPR_ATTRIBUTE (0, SprType6 | 0x0000 , No_Gouraud, CL256Bnk, sprNofilp);

This also specifies that sprite type 6 should be used when specifying the palette.

In either case, specify it in the colno member of the ATTR and SPR_ATTR structures.

・ For slSetSprite

SPRITE spr;
spr.CTRL = FUNC_Sprite;
spr.PMOD = MSBOn | WindowIn | MESHoff | ECenb;
spr.COLR = PrioNo2 | 0x0020;
                  ::
                  ::
And so on, specify the priority number (2 in this case) along with the palette in the color control word of the VDP1 command table.

Also, the priority setting for each sprite type is slPriority or slPrioritySpr? Use a function. (slPrioritySpr? Is a macro.)
As an example

slPriority (scnSPR6, 5);

Or

slPrioritySpr6 (5);

will do.
Is the scroll side slPriorityNBG? And use functions such as slPriorityRBG0.


Rotating the sprite shifts it by 1 dot.

Q)
When I rotate a sprite using a sprite drawing function such as slPutSprite, slDispSpirte, or slSetSprite, the sprite is displayed with a 1-dot shift. How can I fix it?

A)
When rotating a sprite, the center point of rotation is in the center.
In Sega Saturn, the number of dots in the horizontal direction of a sprite is based on a multiple of 8, so if you look at it in dot units, there is no dot that is exactly in the center. Therefore, when rotating the sprite, it will inevitably shift by 1 dot.

This is a Sega Saturn specification, so there is nothing you can do about it, but to avoid the dots shifting, you can either change the display position according to the rotation in the program, or when designing the sprite design, the dots will be rotated. Please respond by drawing a figure that takes into consideration the deviation in advance.


When the sprite is displayed, it looks one dot larger.

Q)
When I displayed the sprite with slDispSprite, a picture that was 1 dot larger than the specified size was displayed. What's the reason.

A)
If you specify 1.00 for the scale with the slDispSprite function, it will be displayed 1 dot larger than the original picture.

This is because the display size is displayed 1 dot larger than the display size specified by the hardware. If you want to avoid this, specify 0.99999 for the scale. This value is defined in SL_DEF.H by a macro called ORIGINAL.


■ | Advance
FAQSGL programming related
Copyright SEGA ENTERPRISES, LTD ,. 1997