jorgemonti
2005.04.04, 07:08 AM
Hi,
Sorry for this lengthy and first thread!
I'm developing an opengl/SDL 2D game. I'm trying to optimize
the rendering process. I've read that the immediate mode is
the slowest, but it's the easiest to implement and it's the
mode i'm using.
I'm renderering only GL_QUADS. My textures comes from bitmapped
files with different size. For instance, my app window is
1024x768, then i have 12 256x256 textures. To render the app
background i've to paint 12 textured quads for every frame.
For the rendering code I only have:
for( unsigned int i = 0; i < m_textures.size(); i++ )
{
// Bind texture.
glBindTexture( GL_TEXTURE_2D, m_textures[i].id );
// Paint polygon.
glBegin( GL_QUADS );
glTexCoord2f( 0.0f,
m_textures[i].height );
glVertex3f( m_textures[i].rect.x,
m_textures[i].rect.y + m_textures[i].rect.h,
0.0f );
glTexCoord2f( m_textures[i].width,
m_textures[i].height );
glVertex3f( m_textures[i].rect.x + m_textures[i].rect.w,
m_textures[i].rect.y + m_textures[i].rect.h,
0.0f );
glTexCoord2f( m_textures[i].width,
0.0f );
glVertex3f( m_textures[i].rect.x + m_textures[i].rect.w,
m_textures[i].rect.y,
0.0f );
glTexCoord2f( 0.0f,
0.0f );
glVertex3f( m_textures[i].rect.x,
m_textures[i].rect.y,
0.0f );
glEnd();
}
So, what's the best way to try to optimize this code? Using display
lists, vertex arrays, vertex buffer objects, using GL_TRIANGLE instead
of GL_QUADS, use STRIPS,... ??
And, if I change the rendering code to dinamically multiply the
vertex with a scale constant, like the next one, but method can i
still use?
for( unsigned int i = 0; i < m_textures.size(); i++ )
{
// Bind texture.
glBindTexture( GL_TEXTURE_2D, m_textures[i].id );
// Paint polygon.
glBegin( GL_QUADS );
glTexCoord2f( 0.0f,
m_textures[i].height );
glVertex3f( m_textures[i].rect.x * scale_x,
(m_textures[i].rect.y + m_textures[i].rect.h) * scale_y,
0.0f );
glTexCoord2f( m_textures[i].width,
m_textures[i].height );
glVertex3f( (m_textures[i].rect.x + m_textures[i].rect.w) * scale_x,
(m_textures[i].rect.y + m_textures[i].rect.h) * scale_y,
0.0f );
glTexCoord2f( m_textures[i].width,
0.0f );
glVertex3f( (m_textures[i].rect.x + m_textures[i].rect.w) * scale_x,
m_textures[i].rect.y * scale_y,
0.0f );
glTexCoord2f( 0.0f,
0.0f );
glVertex3f( m_textures[i].rect.x * scale_x,
m_textures[i].rect.y * scale_y,
0.0f );
glEnd();
}
Any suggestion is welcome!
Thanks,
Jorge
Sorry for this lengthy and first thread!
I'm developing an opengl/SDL 2D game. I'm trying to optimize
the rendering process. I've read that the immediate mode is
the slowest, but it's the easiest to implement and it's the
mode i'm using.
I'm renderering only GL_QUADS. My textures comes from bitmapped
files with different size. For instance, my app window is
1024x768, then i have 12 256x256 textures. To render the app
background i've to paint 12 textured quads for every frame.
For the rendering code I only have:
for( unsigned int i = 0; i < m_textures.size(); i++ )
{
// Bind texture.
glBindTexture( GL_TEXTURE_2D, m_textures[i].id );
// Paint polygon.
glBegin( GL_QUADS );
glTexCoord2f( 0.0f,
m_textures[i].height );
glVertex3f( m_textures[i].rect.x,
m_textures[i].rect.y + m_textures[i].rect.h,
0.0f );
glTexCoord2f( m_textures[i].width,
m_textures[i].height );
glVertex3f( m_textures[i].rect.x + m_textures[i].rect.w,
m_textures[i].rect.y + m_textures[i].rect.h,
0.0f );
glTexCoord2f( m_textures[i].width,
0.0f );
glVertex3f( m_textures[i].rect.x + m_textures[i].rect.w,
m_textures[i].rect.y,
0.0f );
glTexCoord2f( 0.0f,
0.0f );
glVertex3f( m_textures[i].rect.x,
m_textures[i].rect.y,
0.0f );
glEnd();
}
So, what's the best way to try to optimize this code? Using display
lists, vertex arrays, vertex buffer objects, using GL_TRIANGLE instead
of GL_QUADS, use STRIPS,... ??
And, if I change the rendering code to dinamically multiply the
vertex with a scale constant, like the next one, but method can i
still use?
for( unsigned int i = 0; i < m_textures.size(); i++ )
{
// Bind texture.
glBindTexture( GL_TEXTURE_2D, m_textures[i].id );
// Paint polygon.
glBegin( GL_QUADS );
glTexCoord2f( 0.0f,
m_textures[i].height );
glVertex3f( m_textures[i].rect.x * scale_x,
(m_textures[i].rect.y + m_textures[i].rect.h) * scale_y,
0.0f );
glTexCoord2f( m_textures[i].width,
m_textures[i].height );
glVertex3f( (m_textures[i].rect.x + m_textures[i].rect.w) * scale_x,
(m_textures[i].rect.y + m_textures[i].rect.h) * scale_y,
0.0f );
glTexCoord2f( m_textures[i].width,
0.0f );
glVertex3f( (m_textures[i].rect.x + m_textures[i].rect.w) * scale_x,
m_textures[i].rect.y * scale_y,
0.0f );
glTexCoord2f( 0.0f,
0.0f );
glVertex3f( m_textures[i].rect.x * scale_x,
m_textures[i].rect.y * scale_y,
0.0f );
glEnd();
}
Any suggestion is welcome!
Thanks,
Jorge