You are not logged in.

#1 2008-06-24 01:45:17

ats3117
Member

Help with Multiple Printf() Commands and/or textures?

Hi! I'm a complete noob, but I thought I'd try out GRRLIB. So, I started playing with the commands (or whatever they are really called) , and I was confused on how to use more than one GRRLIB_Printf() command.

When I use the following code, The Wii locks up, The screen goes nuts, and no buttons respond. The only solution is to turn it off by holding down the Power button on the console itself.

The solution to this problem might be obvious to you, but I'm stuck. I think that I'm trying to use more than one texture at a time, and I don't know how to do this. Maybe I'm declaring the textures wrong, or maybe something about "pointers" and "casts", because I tried doing different things, and the compiler was giving me fits about things without casts.

Not entirely sure on how to fix it, but any help is greatly appreciated.
-----
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <ogcsys.h>
#include <gccore.h>
#include <wiiuse/wpad.h>
#include <fat.h>

#include "GRRLIB/GRRLIB.h"

#include "GRRLIB/fonts/GRRLIB_font1.h"


Mtx GXmodelView2D;

int main(){

int BoxW = 50;
int BoxH = 75;

int Num = 1;

int XCoord = 100;

//This part may be what I'm doing wrong, not sure...

    u8 *tex_font1=malloc(GRRLIB_font1_size);
   
    *tex_font1=GRRLIB_LoadTexture(GRRLIB_font1);
   
    u8 *tex_font2=malloc(GRRLIB_font1_size);
   
    *tex_font2=GRRLIB_LoadTexture(GRRLIB_font1);
   
    u8 *tex_font3=malloc(GRRLIB_font1_size);
   
    *tex_font3=GRRLIB_LoadTexture(GRRLIB_font1);
   
    u8 *tex_font4=malloc(GRRLIB_font1_size);
   
    *tex_font4=GRRLIB_LoadTexture(GRRLIB_font1);
   
    u8 *tex_font5=malloc(GRRLIB_font1_size);
   
    *tex_font5=GRRLIB_LoadTexture(GRRLIB_font1);
   
    u8 *tex_font6=malloc(GRRLIB_font1_size);
   
    *tex_font6=GRRLIB_LoadTexture(GRRLIB_font1);

// End of the possibly wrong part
   
   
    VIDEO_Init();
    WPAD_Init();

    GRRLIB_InitVideo();
    GRRLIB_Start();

    while(1){
        WPAD_ScanPads();
        u32 wpaddown = WPAD_ButtonsDown(0);
        u32 wpadheld = WPAD_ButtonsHeld(0);

        GRRLIB_FillScreen(0xFFFFFFFF);        
        GRRLIB_Printf(XCoord,120,tex_font1, 0xFFBBBBBB, 1, "Num Value %d", Num);
        GRRLIB_Printf(XCoord,135,tex_font2, 0xFFBBBBBB, 1, "BoxW %d", BoxW);
        GRRLIB_Printf(XCoord,150,tex_font3, 0xFFBBBBBB, 1, "BoxH %i", BoxH);
                       
        GRRLIB_Render();        

        if (wpaddown & WPAD_BUTTON_A) exit(0);
               
    }
    return 0;
}


-----

Again, any help would be greatly appreciated.

Offline

 

#2 2008-06-24 02:30:52

NoNameNo
Administrator

Re: Help with Multiple Printf() Commands and/or textures?

Use 3.0.1 wink 3.0.0 was a little bugged wink sorry

Offline

 

#3 2008-06-25 00:35:04

ats3117
Member

Re: Help with Multiple Printf() Commands and/or textures?

Thanks! Seems to be working now!

Hey, while I'm here, do you know how to declare a string? I tried using the identifier "string" and it says it isn't defined anywhere. I even added #include <string.h> and it still says it's undefined. Any Ideas?

By the way, thanks for pointing out the new update! It just keeps getting better! Keep up the good work!

Offline

 

#4 2008-06-25 00:55:42

RedShade
Member

Re: Help with Multiple Printf() Commands and/or textures?

include near the top of your code

Code:

using namespace std;

Offline

 

#5 2008-06-25 01:07:38

ats3117
Member

Re: Help with Multiple Printf() Commands and/or textures?

This is what I get from the output when I tried that:

---
> "make"
main.c
c:/wii/ogc/newgrrlib/source/main.c:17: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'
c:/wii/ogc/newgrrlib/source/main.c: In function 'main':
c:/wii/ogc/newgrrlib/source/main.c:42: error: 'string' undeclared (first use in this function)
c:/wii/ogc/newgrrlib/source/main.c:42: error: (Each undeclared identifier is reported only once
c:/wii/ogc/newgrrlib/source/main.c:42: error: for each function it appears in.)
c:/wii/ogc/newgrrlib/source/main.c:42: error: expected ';' before 'A'
make[1]: *** [main.o] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
> Time Taken: 00:01
---

By the way,  I'm trying to  Define it like this:

string A = "Test";

Is that wrong? Thanks for your help!

Offline

 

#6 2008-06-25 01:21:41

RedShade
Member

Re: Help with Multiple Printf() Commands and/or textures?

I just noticed that you are using main.c . Strings are Object Oriented, so they'd have to be done coding in C++ I believe. I don't know of any workaround for doing them in C. Switching to C++ (just using *.cpp instead of *.c) would probably make it work though.

For other note:

Namespace declarations are usually done right after your imports at the top of the page.

The error you have says it failed to understand the namespaces statement, so it wouldn't understand string anyway and makes the rest of the errors give very little information.

If you get it working, you should be able to pass the _variable_.c_str to printing functions people have written to make them work, but also benifit from dynamic growing strings and other features in the library.

Last edited by RedShade (2008-06-25 01:24:51)

Offline

 

#7 2008-06-25 01:31:32

ats3117
Member

Re: Help with Multiple Printf() Commands and/or textures?

Okay, so I changed it to a *.cpp and now I have this in the output:

Code:

> "make" 
main.cpp
c:/wii/ogc/newgrrlib/source/main.cpp: In function 'int main()':
c:/wii/ogc/newgrrlib/source/main.cpp:43: error: 'string' was not declared in this scope
c:/wii/ogc/newgrrlib/source/main.cpp:43: error: expected `;' before 'A'
c:/wii/ogc/newgrrlib/source/main.cpp:45: error: invalid conversion from 'void*' to 'u8*'
c:/wii/ogc/newgrrlib/source/main.cpp:65: warning: deprecated conversion from string constant to 'char*'
c:/wii/ogc/newgrrlib/source/main.cpp:66: warning: deprecated conversion from string constant to 'char*'
c:/wii/ogc/newgrrlib/source/main.cpp:67: warning: deprecated conversion from string constant to 'char*'
c:/wii/ogc/newgrrlib/source/main.cpp:68: warning: deprecated conversion from string constant to 'char*'
c:/wii/ogc/newgrrlib/source/main.cpp:69: warning: deprecated conversion from string constant to 'char*'
c:/wii/ogc/newgrrlib/source/GRRLIB/GRRLIB.h: At global scope:
c:/wii/ogc/newgrrlib/source/GRRLIB/GRRLIB.h:21: warning: inline function 'void GRRLIB_FillScreen(u32)' used but never defined
c:/wii/ogc/newgrrlib/source/GRRLIB/GRRLIB.h:26: warning: inline function 'void GRRLIB_Line(f32, f32, f32, f32, u32)' used but never defined
c:/wii/ogc/newgrrlib/source/GRRLIB/GRRLIB.h:28: warning: inline function 'void GRRLIB_Rectangle(f32, f32, f32, f32, u32, u8)' used but never defined
make[1]: *** [main.o] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
> Time Taken: 00:01

When you say that Namespace declarations are usually done right after the imports, do you mean after all of the #include <something.h> lines? If so, I think I have that.

This is what I have at the top of my code:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <ogcsys.h>
#include <gccore.h>
#include <wiiuse/wpad.h>
#include <fat.h>

#include "GRRLIB/GRRLIB.h"

#include "GRRLIB/fonts/GRRLIB_font1.h"

using namespace std;


Mtx GXmodelView2D;

int main(){
//rest of the code...

Thanks for the help.

Sorry if I'm doing something really stupid...


Well, for now, I'll leave it as a *.c, and just not mess with it. It sounds a bit complicated, so it should be fine untill I figure it out later.

Thanks for all of the help!

Last edited by ats3117 (2008-06-25 01:48:55)

Offline

 

#8 2008-06-25 01:41:15

RedShade
Member

Re: Help with Multiple Printf() Commands and/or textures?

Mostly me forgetting or not noticing things.
<string> is the string C++ library, the one that you want.
<string.h> is the c_string C library.

This may be a bit more helpful than repeated posts.
http://www.cprogramming.com/tutorial/string.html

Offline

 

#9 2008-06-25 02:58:51

ats3117
Member

Re: Help with Multiple Printf() Commands and/or textures?

Sorry, but I need to ask one more question.

I have it saved as a *.cpp, and it is running into an error. It says:

c:/wii/ogc/newgrrlib/source/main.cpp:43: error: invalid conversion from 'void*' to 'u8*'

The line it's talking about says:

u8 *tex_font1=malloc(GRRLIB_font1_size);

tex_font1=GRRLIB_LoadTexture(GRRLIB_font1);

So, when I go to use it in a GRRLIB_Printf() command, it needs it as a 'u8', not a 'void'.

Is there a solution to this?

Again, thanks for all of your help!

Nevermind, I just got it to work as a C++. Thanks for everything!

Last edited by ats3117 (2008-06-25 03:23:49)

Offline

 

#10 2008-07-10 18:46:03

aquilino
Member

Re: Help with Multiple Printf() Commands and/or textures?

try to set them friend:

u8 *tex_font1=malloc(GRRLIB_font1_size),
   
    *tex_font1=GRRLIB_LoadTexture(GRRLIB_font1),
   
    *tex_font2=malloc(GRRLIB_font1_size),
   
    *tex_font2=GRRLIB_LoadTexture(GRRLIB_font1),
   
    *tex_font3=malloc(GRRLIB_font1_size),
   
    *tex_font3=GRRLIB_LoadTexture(GRRLIB_font1),
   
     *tex_font4=malloc(GRRLIB_font1_size),
   
    *tex_font4=GRRLIB_LoadTexture(GRRLIB_font1),
   
    *tex_font5=malloc(GRRLIB_font1_size),
   
    *tex_font5=GRRLIB_LoadTexture(GRRLIB_font1),
   
    *tex_font6=malloc(GRRLIB_font1_size),
   
    *tex_font6=GRRLIB_LoadTexture(GRRLIB_font1);

Offline

 

#11 2008-07-10 22:00:22

RedShade
Member

Re: Help with Multiple Printf() Commands and/or textures?

I'm confused what that is trying to do beyond leak a lot of memory...

Code:

  //allocates a bit of memory (not suitable for texture if that was the intent), use memalign(32,size)
    *tex_font5=malloc(GRRLIB_font1_size), 
 //erases the pointer done in the previous line, leaking memory
    *tex_font5=GRRLIB_LoadTexture(GRRLIB_font1),

If you are using the current library, all you need to do is:

Code:

u8 *tex_fontX = GRRLIB_LoadTexture(GRRLIB_fontX);

side note:

Code:

*text_fontX = GRRLIB_LoadTexture(GRRLIB_fontX);

is the same as

Code:

text_fontX[0] = GRRLIB_LoadTexture(GRRLIB_fontX);

Last edited by RedShade (2008-07-10 22:09:55)

Offline

 

Board footer

Powered by FluxBB