PDA

View Full Version : Textures, bitmap and screen



LucaFr
12-02-2008, 07:28 AM
Hi folks,

i am a newbie with opengl and i need to do the following thing. I have a opengl surface of 320x240. I have a bitmap of 320x240. I need to cover the surface with the bitmap so that when i display it on the screen, the bitmap is completely visible. I cannot use glDrawPixels.

I know that i have to use two quad. I want to create one texture of 256x256, copy the 256x240 part of the bitmap on it, leaving the last 16 lines blank. Than i want to create a texture of 64x256, copy the other 64x240 part of the bitmap, leaving the last 16 lines blank. Than i want to use those textures to texture two quad that cover the entire surface (to make it faster, i wanto to disable perspective correction).

I have tried all of this but i cannot show it right (actually, i am using Opengl Es on a mobile device). The application crashes...

Someone here can help me? Some code/link would be really useful!!! :P

Thank you,
Luca

_NK47
12-02-2008, 07:43 AM
you need to setup orthogonal projection (glOrtho) and create textures from a bitmap before rendering the quads. if your card supports non power of two textures or texture rectangles you dont have to split the bitmap. im not familiar with ES though.

would help to know what is not correct in your app atm.

LucaFr
12-02-2008, 08:33 AM
I don't know, i would like to try someone else code in order. Here it is the code. I have omitted all, i was trying to draw a simple quad but it crashes anyway :(
(i have taken this code from another forum, it use only a 256x256 texture, but i tought that was a good starting point)


//==========================================
// BACKGROUND PLANE
static const GLbyte bgverts[8] =
//static const GLfloat bgverts[8] =
{
/*0, 0,
1.06, 0,//1, 0,
0, 0.8,//0, 1,
1.06, 0.8//1, 1
*/
0, 0,
1, 0,
0, 1,
1, 1
};

static const GLubyte bgtex[8] =
{
0, 1,
1, 1,
0, 0,
1, 0
};



void RenderTexturedBG(TUint8* aCamFrameData)
{
GLuint iTexturesID[10];

/*
// Textures are initialized in OpenGL ES API by this function.
glGenTextures( 1, iTexturesID );
glBindTexture( GL_TEXTURE_2D, iTexturesID[0] );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 256, 256,
0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)aCamFrameData );
//glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 256, 256,
// 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)aCamFrameData );
glTexEnvx( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);*/

// Before drawing the background texture, we need to switch to ortho (2D) mode.
// Passing 1 instead of the implicit size of screen will make OpeGL use the full size of screen (1:1)
//OrthoMode(0, 1, 0, 1);
// Switch to our projection matrix so that we can change it to ortho mode, not perspective.
glMatrixMode(GL_PROJECTION);
// Push on a new matrix so that we can just pop it off to go back to perspective mode
glPushMatrix();

glDisable( GL_DEPTH_TEST );
glDisable( GL_CULL_FACE );

// Reset the current matrix to our identify matrix
glLoadIdentity();
// Pass in our 2D ortho screen coordinates (left, right, bottom, top, near, far).
//glOrthof( aLeft, aRight, aBottom, aTop, -1, 1 );
glOrthof(0, 1, 0, 1, -1, 1);
//glOrthof(0, 1/0.8, 0, 1/0.53, -1, 1);

// Switch to model view so that we can render the texture
glMatrixMode(GL_MODELVIEW);
// Initialize the current model view matrix with the identity matrix
glLoadIdentity();
//glEnable(GL_TEXTURE_2D);


//DrawBGPoly();
//glPushMatrix();
// Enable vertex arrays.
//glEnableClientState( GL_VERTEX_ARRAY );
// Set array pointers.
glVertexPointer( 2, GL_BYTE, 0, bgverts );
//glVertexPointer( 2, GL_FLOAT, 0, bgverts);
// Enable texture arrays
//glEnableClientState( GL_TEXTURE_COORD_ARRAY );
// Set texture coords
//glTexCoordPointer( 2, GL_BYTE, 0, bgtex );

//glBindTexture( GL_TEXTURE_2D, iTexturesID[0] );
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
//glDisable(GL_TEXTURE_2D);
//glDisableClientState(GL_TEXTURE_COORD_ARRAY);
//glDisableClientState(GL_VERTEX_ARRAY);
//glPopMatrix();




//PerspectiveMode();
// Load our projection matrix
glMatrixMode( GL_PROJECTION );
glEnable( GL_DEPTH_TEST );
glEnable( GL_CULL_FACE );

// Get rid of ortho mode which was lst pushed in the projection matrix mode
glPopMatrix();
// Go back to model view matrix
glMatrixMode( GL_MODELVIEW );


//glDeleteTextures(1, iTexturesID);
}

dletozeun
12-03-2008, 09:00 AM
Your code is quite unreadable and full of weird things, I mean, many useless things but these one should not make crash you application. Why did you comment many lines? There are useful things especially to use the vertex array that are commented, like enabling vertex array client state...

Without wanting to offend you, you really need to restructure your code, dividing it in several functions for in initialization, rendering... That would really help you to solve your problem.

LucaFr
12-03-2008, 05:02 PM
Yes i know, that code was an experiment only. Finally i have made it! The problem was not disabling normal coordinates pointer (which was enabled for other things)...
Thanks