Basic syntax issue with VDP_drawImageEx();

SGDK only sub forum

Moderator: Stef

Post Reply
Munkyears
Very interested
Posts: 54
Joined: Sat Mar 21, 2009 4:24 pm
Location: Sheffield, England

Basic syntax issue with VDP_drawImageEx();

Post by Munkyears » Mon Sep 10, 2018 3:32 am

Hi Guys!
So good to see this place is still up and running!!
Its been 9 years since I started here, Still struggling with simple syntax errors!

Could someone please advise me?
Simply trying to draw an image specifically a .PNG file, adequately formatted however Code::Blocks doesnt want to compile to following:

Code: Select all

    // screen w
    VDP_setScreenWidth320();
    VDP_setPaletteColors(0, palette_black, 64);

    //Initialise pad
    JOY_init();

    //draw the background
    VDP_drawImageEx(PLAN_B, &ponyologo_image, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 0, 0, FALSE, TRUE);
    ind += ponyologo_image.tileset->numTile;

    //draw ponyo large
    //HOLD OFF ON THIS FOR NOW
    //VDP_drawImageEx(PLAN_A, &gamelogo, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, tileIndex), 7, 4, TRUE, TRUE);
    //tileIndex += gamelogo.tileset->numTile;

    //draw logo ponyo
   // VDP_drawImageEx(PLAN_A, &ponyologo_image, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, tileIndex), 7, 4, TRUE, TRUE);
   // tileIndex += ponyologo_image.tileset->numTile;
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //Initialize sprite engine
    //SPR_init(256);
However this is the following output:
help.png
help.png (38.7 KiB) Viewed 7337 times
I am bewildered but it is 4.30am in England!! :D :D :D

Thanks for your support!! Finally putting my efforts to some use!!

Hope you are all well! :)

@KanedaFr - Please keep SMForums going please!! Always been my go to escape even if I just lurk :D
To be this good takes ages, To be this good takes Stef, Kanedafr, ChillyWilly & everyone who has helped me discover what hardwork is!

Dive into the SpritesMind! :)

Grind
Very interested
Posts: 69
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

Re: Basic syntax issue with VDP_drawImageEx();

Post by Grind » Mon Sep 10, 2018 1:56 pm

There could be something about the previous line it doesn't like, but it looks fine to me. Is "ind" supposed to be the name of the variable here? That doesn't match the code snippet above.

My other guess is there is an extra "}" somewhere that didn't get commented with the rest of its block.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Basic syntax issue with VDP_drawImageEx();

Post by Stef » Mon Sep 10, 2018 2:12 pm

Ca you show the content of the generated gfx.h file ?
It looks like the compiler don't like the auto generated DEFINE directive name. This one is generated from the resource file path so i guess you have a weird character into your file path.

Munkyears
Very interested
Posts: 54
Joined: Sat Mar 21, 2009 4:24 pm
Location: Sheffield, England

Re: Basic syntax issue with VDP_drawImageEx();

Post by Munkyears » Mon Sep 10, 2018 2:27 pm

Thanks for your reply!

Code: Select all

#ifndef _C_\SGDK\PONYO\RES_GFX_H_
#define _C_\SGDK\PONYO\RES_GFX_H_

#endif
this is the output from the gfx.res
I forwent having multiple res files for SPRITE & IMAGE like your example.
I did have to place #endif as it kept throwing errors

Now after coming back to this, I cannot seem to recreate the same error. Now it throws ponyologo_image is undefined, even when I have specifically listed it inside GFX.res

Here is the main in its entirety:

Code: Select all

 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <genesis.h>
#include "res/gfx.h"
#include "res/sound.h"
// DOC.TXT - For Documentation Help!! stored in C:\SGDK or Desktop!
// UPDATE THIS FOR EVERYTHING YOU DO!
// IF YOU FALL ASLEEP AND FORGET ALL THIS!
#define ANIM_STATIC  0
#define ANIM_SCORE   1
#define ANIM_BRONZE  2
#define ANIM_SILVER  3
#define ANIM_GOLD    4
#define ANIM_PLATIN  5
#define ANIM_INSTR   6
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define GRAVITY         FIX16(0.4)
#define MIN_POSX        FIX16(10)
#define MAX_POSX        FIX16(280)
#define MAX_POSY        FIX16(154)
#define SLIDESPEED      FIX16(6)
#define FALSE 0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define TITLE   0 //SPLIT INTO SECTIONS TO MANAGE SUB ROUTINES BETTER
#define INTRO   1 //THIS IS GOOD PRACTICE
#define GAME    2 // NUMBER RELATES TO ORDER
#define INSTRUCTIONS 3//
#define MAX_SPRITE 16 // HOWEVER THIS SEEMS TO LIMIT WHATS AVAILABLE
//MAY HAVE TO LOOK AT SPLITTING LEVELS INTO SUBROUTINES
//I.E LOAD TITLE, FINISH GOTO GAME, FINISH GAME GOTO GAME 2 (LEVEL 2)
//LOOK AT IN FUTURE, CONCENTRATE ON
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//structure as follows,
// PLAN_A = Foreground, 1 = HP
// PLAN_B = Foreground, 0 = LP
// PLAN_B = Background, 1 = HP
// PLAN_B = Background, 0 = LP
// THIS MIMICS DEPTH PERCEPTION!
// DONT FORGET!
// WINDOW PLANE (PLAN_W??) IS STATIC AND STAYS AS HUD, NON SCROLLABLE
// After TILE_ATTR etc...
// PAL0 = Palette 0
// 0 = Priority high - 1 = Priority low

// VDP_drawImageEx(PLAN_B, &plan_b1, TILE_ATTR_FULL(PAL0, 0, FALSE, FALSE, ind), 0, 30, FALSE, TRUE);
// ind += plan_b1.tileset->numTile;


 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// forward
static void disableInts(); // DECLARING INTERRUPTS OF VDP
static void enableInts();

static void joyEvent(u16 joy, u16 changed, u16 state); // JOYPAD READ

static void introJoyEvent(u16 joy, u16 changed, u16 state); // INTRODUCE JOYPAD
static void gameJoyEvent(u16 joy, u16 changed, u16 state); // READY FOR GAME, I THINK??
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// sprite structure
//Sprite allsprites[MAX_SPRITE];
//Sprite sprponyo = &allsprites[0];
//Sprite sprinstr = &allsprites[1];
Sprite sprites[MAX_SPRITE];
//Sprite sprflappy = &sprites[0];
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
fix16 camposx; // CAMERA POSITION X
fix16 camposy; // CAMERA POSITION Y
fix16 posx; // X PLACEMENT
fix16 posy; // Y PLACEMENT
fix16 movx; // MOVE POSITION X
fix16 movy; // MOVE POSITION Y
s16 xorder; // ??
s16 yorder; // ??
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int gamestate = TITLE;
int music_status;


volatile int waitflag = FALSE;
int score = 0; // SCORE TRACKER FOR LATER
int PonyoTitlePosition = 250;
char ponyoPosString;
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()

{
//Title screen
    u16 tileIndex = TILE_USERINDEX;
    u16 ind = tileIndex;
    u16 palette[64]; //64 = 8*8 Palette

    //play VGM
    //SND_startPlay_XGM(ponyo_music.vgm);

    // screen w
    VDP_setScreenWidth320();
    VDP_setPaletteColors(0, palette_black, 64);

    //Initialise pad
    JOY_init();

    //draw the background
    VDP_drawImageEx(PLAN_B, &ponyologo_image, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, tileIndex), 0, 0, FALSE, TRUE);
    ind += ponyologo_image.tileset->numTile;

    //draw ponyo large
    //HOLD OFF ON THIS FOR NOW
    //VDP_drawImageEx(PLAN_A, &gamelogo, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, tileIndex), 7, 4, TRUE, TRUE);
    //tileIndex += gamelogo.tileset->numTile;

    //draw logo ponyo
   //VDP_drawImage(PLAN_A, ponyologo_image, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, tileIndex), 7, 4, TRUE, TRUE);
   // tileIndex += ponyologo_image.tileset->numTile;
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //Initialize sprite engine
    //SPR_init(256);

    //Draw the title screen text
    VDP_drawText("* Press START *", 8, 12);
    VDP_drawText("By Joseph Ioannou (53K70R)", 7, 26);

    camposx = FIX16(0);
    camposy = FIX16(0);
    posx = FIX16(250);
    posy = FIX16(42);
    movx = FIX16(0);
    movy = FIX16(0);
    xorder = 0;
    yorder = 0;

    // initialize the sprite (Flappy! :D)
    //SPR_initSprite(&sprites[0], &flappy_sprite, fix16ToInt(posx), fix16ToInt(posy), TILE_ATTR(PAL0, TRUE, FALSE, FALSE));
    //SPR_update(&sprites[0], 1);


    // prepare the palette
    //memcpy(&palette[0], bga_image.palette->data, 16*2);
    //memcpy(&palette[16], ponyologo.palette->data, 16*2);
    //memcpy(&palette[32], flappy_sprite.palette->data, 16*2);
    JOY_setEventHandler(joyEvent);




 while(TRUE)
 {
   switch(gamestate)
   {
      case INTRO:
        //updateIntroAnim();
        //Clear the A Plane to remove the logo and title screen text
        VDP_clearPlan(PLAN_A, FALSE);


        //ponyo movement
        //for (flappyTitlePosition; flappyTitlePosition>0; flappyTitlePosition--)
        //{
        //   SPR_setPosition(&sprites[0], ponyoTitlePosition, fix16ToInt(posy));
        //    SPR_update(&sprites, 2);
        //    VDP_waitVSync();
        //}
        //VDP_waitVSync();
        //stop playing music
        //SND_stopPlay_VGM();

        //SPR_initSprite(&sprites[1], &ponyo_sprite, 140, 80, TILE_ATTR(PAL0, TRUE, FALSE, FALSE));
        //SPR_setAnim(&sprites[1], ANIM_INSTR);

        //SPR_update(&sprites, 2);

        VDP_waitVSync();

        gamestate = INSTRUCTIONS;


        break;

      case GAME:

        //updateGameAnim();
        SPR_setPosition(&sprites[1], -100, -100);
        VDP_drawText("Score:", 0, 0);
        //SND_stopPlay_VGM();

        //update sprites
        //disableInts();
        SPR_update(&sprites, 2);
        //enableInts();
        VDP_waitVSync();
        JOY_setEventHandler(gameJoyEvent);
        break;

      case INSTRUCTIONS:

        //updateGameAnim();
        JOY_setEventHandler(introJoyEvent);


        //update sprites
        //disableInts();
        SPR_update(&sprites, 2);

        //enableInts();
        VDP_waitVSync();
        break;


      case TITLE:

        disableInts();
        SPR_update(&sprites, 1);
        enableInts();
        VDP_waitVSync();
        break;


    }
 }

return 0;

}




static void disableInts()
{
    if (!SYS_isInInterrupt()) SYS_disableInts();
}

static void enableInts()
{
    if (!SYS_isInInterrupt()) SYS_enableInts();
}


static void introJoyEvent(u16 joy, u16 changed, u16 state)
{
    // START button state changed
    if (changed & BUTTON_START)
    {

    }

    if (changed & state & (BUTTON_A | BUTTON_B | BUTTON_C))
    {
        gamestate = GAME;

    }
}

static void gameJoyEvent(u16 joy, u16 changed, u16 state)
{
    // START button state changed
    if (changed & BUTTON_START)
    {

    }

    //if (changed & state & (BUTTON_A | BUTTON_B | BUTTON_C))
    {
        //SND_startPlayPCM_XGM(ponyo_jump, 1, SOUND_PCM_CH4);
        //SND_startPlay_VGM(ponyo_music.vgm);


    }
}

static void joyEvent(u16 joy, u16 changed, u16 state)
{
    // START button state changed
    if (changed & BUTTON_START)
    {
        gamestate = INTRO;
    }

    if (changed & state & (BUTTON_A | BUTTON_B | BUTTON_C))
    {


    }
}
Ignore my silly comments :) :) I'm learning haha!

Cheers!
To be this good takes ages, To be this good takes Stef, Kanedafr, ChillyWilly & everyone who has helped me discover what hardwork is!

Dive into the SpritesMind! :)

Munkyears
Very interested
Posts: 54
Joined: Sat Mar 21, 2009 4:24 pm
Location: Sheffield, England

Re: Basic syntax issue with VDP_drawImageEx();

Post by Munkyears » Mon Sep 10, 2018 2:59 pm

As I noticed you declared,

Code: Select all

extern const Image 

in your gfx.res

I also changed:

Code: Select all

#ifndef _C_\SGDK\PONYO\RES_GFX_H_
#define _C_\SGDK\PONYO\RES_GFX_H_
to:

Code: Select all

#ifndef _RES_GFX_H_
#define _RES_GFX_H_
still to no avail. even if I try to compile your sprite.cbp, It still throws undeclared images,

I sense I have to problem solve & reinstall SGDK 1.34 & possibly write it again as I havent made too much progress
I'll wait for a reply first before I do :)
Thanks!!
To be this good takes ages, To be this good takes Stef, Kanedafr, ChillyWilly & everyone who has helped me discover what hardwork is!

Dive into the SpritesMind! :)

Munkyears
Very interested
Posts: 54
Joined: Sat Mar 21, 2009 4:24 pm
Location: Sheffield, England

Re: Basic syntax issue with VDP_drawImageEx();

Post by Munkyears » Mon Sep 10, 2018 5:08 pm

Apologies for the repeated posts but I think ResComp seems to have an issue with compiling.

If I change anything from within .res files for instances (s1_jump.wav) to (s2_jump.wav) & ResComp it,
then recompile the whole build, it causes them become undefined even though the context hasnt changed, only the file names??

Has rescomp had an update since SGDK 1.34? I'm hoping this is a simple fix!!
To be this good takes ages, To be this good takes Stef, Kanedafr, ChillyWilly & everyone who has helped me discover what hardwork is!

Dive into the SpritesMind! :)

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Basic syntax issue with VDP_drawImageEx();

Post by Stef » Tue Sep 11, 2018 8:07 pm

Sorry, i tried to investigate the problem : I re-installed a fresh SGDK 1.34 but i just cannot replicate your problem.
I had an issue in the github repository where the bintos tool was buggy (i just updated it) but you shouldn't be impacted by it.
It seems like your rescomp isn't correctly generating resource name... i will continue investigations.

Munkyears
Very interested
Posts: 54
Joined: Sat Mar 21, 2009 4:24 pm
Location: Sheffield, England

Re: Basic syntax issue with VDP_drawImageEx();

Post by Munkyears » Wed Sep 12, 2018 10:57 am

Thanks for the reply. I wonder if its due to my OS? Running Windows 10 x64 16gb DDR4. Noticed a few issues occasionally with make.exe.

Cannot quote directly as replying from mobile as not at home but something along the lines of "-child died waiting for...." resource is currently unavailable.

I assumed it was something halting resource allocation around CPU/Ram. Going to try install a Windows XP VM and see if i can fix the issue later on today.

Thanks for your help Stef!! Glad to see you are still around!! Btw are you still working on SGDK? I know you are a very busy man, and a clever one!!

Cheers!

[UPDATE] Problem seems to have been solved running SGDK & CB under Windows XP via VMware! Cheers
To be this good takes ages, To be this good takes Stef, Kanedafr, ChillyWilly & everyone who has helped me discover what hardwork is!

Dive into the SpritesMind! :)

Post Reply