PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

N95 OpenGL Question

Hello,

I am using the following code to draw a box on screen... using existing Projection & Modelview Matrix's

glMatrixMode(GL_PROJECTION);
glLoadMatrixf( getProjectionMatrix() );
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf( getModelViewMatrix() );
DrawBox( 20.f, 20.f, 20.f, 0 );

How do I code the same thing with EdgeLib?

i.e. Using my own Projection & Model Matrix's. What do I need to change below? (Taken From the Animate3D Turtle demo.)



display->Perspective3D(display->GetWidth(), display->GetHeight());
display->WorldReset();
display->WorldTranslate(0, 0, zoom);
#if !defined(EGL_USEGL)
display->WorldScale(65536 * 2, 65536 * 2, 65536 * 2);
#endif
display->WorldRotate(256, 0, 0);
display->WorldRotate(0, rotation, 0);
display->BindTexture(█_tex);
display->SetShading(E3D_GOURAUD | E3D_TEXTURE);
display->Render(█);

turtle.Animate(anitimer / 2);
display->BindTexture(&turtle;_tex);
display->SetShading(rendertype_shading[rendertype]);
display->Render(&turtle;);
Hi Lance,

If you want to use your own projection matrix, you can call the native OpenGL functions (glMatrixMode and glLoadMatrixf) just after Perspective3D. Don't forget to change the matrix mode to GL_MODELVIEW afterwards.

To use custom model matrices we recommend locking the surface before a call to display->Render(). Then you can modify its matrix. However, a conversion to fixed point must be made to both the vertex coordinates and matrices.
lanceabson · 02 May 2008, 13:49 UTC — Re Model Matrix
Hello,

Thank you for your reply.

I have got the Projection matrix part working, but not the model matrix.
Do you have some example code to do what you are explaining so that I can use my own model matrix?

Kind Regards,
Lance
Hi Lance,

Here is a sample:

Code:

E3DSURFACEINFO info;
if (model.Lock(&info))
{
for (int i = 0; i < 16; i++)
info.matrix[i] = (int)(yourmatrix[i] * 4096);
model.Unlock();
}


The matrix uses 20:12 fixed point values.
lanceabson · 02 May 2008, 16:15 UTC — Re Model Matrix
Hello, Thank you again for a quick reply.

I have used your code as below but now no model is displaying.


This Bit Works displaying my own box model....

glMatrixMode(GL_PROJECTION);
glLoadMatrixf( &Proj_Mat_Buff_0[0] );
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf( &View_Mat_Buff_0[0] );

glDrawElements( GL_TRIANGLES, 48 * 3, _UNSIGNED_BYTE, objTriangles); //BOX OBJECT


But this is not displaying anything....

display->Perspective3D(display->GetWidth(), display->GetHeight());

glMatrixMode(GL_PROJECTION);
glLoadMatrixf( &Proj_Mat_Buff_0[0] );
glMatrixMode(GL_MODELVIEW);

E3DSURFACEINFO info;
if (turtle.Lock(&info))
{
for (int i = 0; i < 16; i++)
info.matrix[i] = (int)(View_Mat_Buff_0[ i ] * 4096);
turtle.Unlock();
}

turtle.Animate(anitimer / 2);
display->BindTexture(&turtle_tex);
display->SetShading(rendertype_shading[rendertype]);
display->Render(&turtle);
Hi Lance,

I think the error is caused by the values in your matrix. You might want to change the multiplier (now it is set to 4096) so it better matches your projection matrix. In my sample I used 4096 because with the EDGELIB Perspective3D function, x/y coordinates of -4096 to 4096 are shown onscreen.