gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS Misc > Problems with OpenGL

#160135 - BenRK - Thu Jul 10, 2008 8:07 pm

I'm having problems using OpenGL in a project of mine. I want to move stuff around on the screen by pixels (not by the leaps and bounds that floats do), but I haven't found any apparent standard in the OpenGL functions to get the translation to not use floats. So, I tried applying the changes in the y value to the quad it self, but nothing on the screen moved at all. So, either changing vertex coordinates in real time is not possible with out a translation, or my screen isn't refreshing for one reason or another. So, I've come here for help.

Code:
while (1)
{
   if (keysHeld() & KEY_UP)
      {
      camy--;
      }
                 
      //ds specific, several attributes can be set here   
      glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
      
      // Set the current matrix to be the model matrix
      glMatrixMode(GL_MODELVIEW);
      
      //Push our original Matrix onto the stack (save state)
      glPushMatrix();
 
glBegin(GL_QUADS);
   glColor3b(37,69,150);
   glVertex3v16(0,camy,0);
   
   glColor3b(36,68,149);
   glVertex3v16(256,camy,0);
   
   glColor3b(11,118,193);
   glVertex3v16(256,600+camy,0);
   
   glColor3b(12,119,194);
   glVertex3v16(0,600+camy,0);
glEnd();
      
      // Pop our Matrix from the stack (restore state)
      glPopMatrix(1);

      //a handy little built in function to wait for a screen refresh
      swiWaitForVBlank();
      
      // flush to screen   
      glFlush(0);
   
   }

_________________
EvolitesDS - Possibly coming out some day... maybe...

#160139 - silent_code - Thu Jul 10, 2008 9:07 pm

The problem is, that there is no OpenGL. ;^)

What you mean is libnds' videoGL. Don't confuse the two APIs. ;^)

You can achieve what you want (this is just one possible solution) with a glTranslatef32() in fixed point after pushing the matrix and before sending geometry commands. That way you can have more or less fixed geometry.

Another thing: Call swiWaitForVBlank() after flushing! It should be pretty much the last thing you call in a frame, because it means "Oh, we have nothing more to do this frame, so, just sit there idling until the next frame starts." (Feel free to correct me on this.) ;^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#160150 - BenRK - Thu Jul 10, 2008 10:32 pm

Well, now I'm just getting an error, saying there's an undefined reference to glTranslatef32. Heh, I know I'm doing something wrong, as I'm rather new at OpenGL, er, videoGL. I'm not trying to create complicated geometry, just a quad, various 12-gons, a wireframe of said 12-gons, and various 3D sprites, all on a 2D plane (just so you know).

Code:
glLoadIdentity();
glTranslatef32(0,camy,0);
glBegin(GL_QUADS);
   glColor3b(37,69,150);
   glVertex3v16(0,0,0);
   
   glColor3b(36,68,149);
   glVertex3v16(256,0,0);
   
   glColor3b(11,118,193);
   glVertex3v16(256,600,0);
   
   glColor3b(12,119,194);
   glVertex3v16(0,600,0);
glEnd();


And I switched around glFlush() and sqiWaitForVBlank().

Edit, well, I believe the game isn't refreshing for some reason, and I really don't know why.
_________________
EvolitesDS - Possibly coming out some day... maybe...

#160221 - zeruda - Sat Jul 12, 2008 5:05 am

BenRK wrote:
Well, now I'm just getting an error, saying there's an undefined reference to glTranslatef32.


In VideoGL the command is glTranslate3f32.

What I suggest is you go to the devkitpro/libnds/include folder. All the header files are there. In particular look at devkitpro/libnds/include/nds/arm9/videoGL.h. Apart from that I suggest you go through the examples located in the devkitpro/examples folder.

#160256 - BenRK - Sat Jul 12, 2008 11:07 pm

Well, it's also not showing any input. I have a value that is supposed to be subtracted when I press up. Should be simple, but nothing happens when I press up, both on hardware and an emulator.
_________________
EvolitesDS - Possibly coming out some day... maybe...

#160268 - zeruda - Sun Jul 13, 2008 2:53 am

Like I said, go and look at the examples that come with devkitpro. Theres working examples covering input, sound, 2d and 3d graphics amongst other things. Compile and run those, and then you can go from there.

#160274 - BenRK - Sun Jul 13, 2008 8:06 am

Seriously, why don't people do that? Just looking at the input examples fixed my last problem (for now). I wasn't reading the button states. Now it's working how I wanted it to! Thank-you!
_________________
EvolitesDS - Possibly coming out some day... maybe...