Create the 3D object in question, without displaying it.
You can get the bounds of the object as pixel locations by using gluProject (to get the pixels that represent the object's edges. You can then use gluUnProject to map the intervening pixels to the object's coordinates.
Then, you start your draw over, and map a custom (on-the-fly) texture over the same object and display it.
Not sure why you'd want to do this, but that should be a good starting point.
Edit:
What I mean by custom, is if the bounds of your object (in one dimension,) are -3.0 to 1.0, and the first pixel row is from -3.0 to -2.0, your texture map is going to indicate that 25% of your custom texture maps over that spot, and you create it all with the color of the pixel you want to show there.
After thinking that through, I realized you could just draw a texture over the top of the projected screen coordinates (using the 2D drawing facilities.)
I think that gets the gist of your idea across. I don't think it would work well in an interactive 3D demo, if the 'object' comes closer and moves away, if the texture doesn't seem to scale up and down. But you didn't say what you were actually doing.
Edit 2:
OpenGL 2D Projection:
CAUTION
Careful with the function names, e.g., opengles 1.1 has glOrthox and glOrthof. Make sure you check what is available in your gl.h header file.
const XSize = 640, YSize = 480 glMatrixMode (GL_PROJECTION) glLoadIdentity () glOrtho (0, XSize, YSize, 0, 0, 1) glMatrixMode (GL_MODELVIEW) glDisable(GL_DEPTH_TEST) glClear(GL_COLOR_BUFFER_BIT) // Now draw with 2i or 2f vertices instead of the normal vertex3f functions. // And for ES, of course set up your data structures and call drawarrays ofr drawelements. SwapBuffers()
This will allow you to draw 2D shapes in OpenGL (much more simply than using 3D projections.) To mix the two, e.g., draw in 3D then in 2D, follow the second link.
Here's an excellent tutorial on 2D drawing:
http://basic4gl.wikispaces.com/2D+Drawing+in+OpenGL
Here's the basics on mixing the two:
http://www.gamedev.net/community/forums/topic.asp?topic_id=96440
I hope that is what you want. I get a sneaking suspicion from your post that you're having trouble mapping your texture across triangle points to make it show up 'straight'. You might want to review basic texture mapping on NeHe:
http://www.gamedev.net/community/forums/topic.asp?topic_id=96440
E.g., gltexcoord2f specifies the point (0.0-1.0) within the texture in terms of the percentage of width and height of the texture that maps to the next drawn vertex. With triangle fans, you can have some mathematical conniptions to figure out what % of width and height of the overall object you are specifying with the vertex.
Take, for example, a sphere with a texture map (a mercator projection of the earth,) is best mapped by calculating the lines of latitude as a basis for your underlying triangle fan vertex values, as it eases calculation of the texture coordinates. Making your polygons approximate simple geometric shapes allows you to use trigonometry to more easily calculate texture coordinates.
I hope this is helpful.
Hehere, I'll quit going on with desktop examples you have to modifiy. Here's an OpenGLES example that does proper 3D texture mapping. You can use what I said above, and this example, to do 2D texture mapping.
http://www.zeuscmd.com/tutorials/opengles/17-TextureMapping.php
I think the following code snippet is what you're talking about. However, without the hack in reshape() it shimmers pretty badly with GL_NEAREST and non-even viewport sizes. Any insight would be appreciated.
It uses texture coordinate generation though, so I'm not sure what to tell you on the OpenGL ES 1.1 front. A PowerVR rep hinted at a solution, but wasn't very explicit.
#include #include #include static GLuint texName; void init(void) { glClearColor(0,0,0,0); // create random texture const int texWidth = 8; const int texHeight = 8; GLubyte tex[texHeight][texWidth][4]; for(int i = 0; i
EDIT: Got the texture matrix only method figured out (should be OpenGL ES 1.1-able):
#include #include #include void glutTexturedCube(GLdouble size) { GLfloat texc[] = { 1,1, 0,1, 0,0, 1,0, 0,1, 0,0, 1,0, 1,1, 1,0, 1,1, 0,1, 0,0, 1,1, 0,1, 0,0, 1,0, 0,0, 1,0, 1,1, 0,1, 0,0, 1,0, 1,1, 0,1, }; GLfloat norm[] = { 0,0,1, 0,0,1, 0,0,1, 0,0,1, 1,0,0, 1,0,0, 1,0,0, 1,0,0, 0,1,0, 0,1,0, 0,1,0, 0,1,0, -1,0,0, -1,0,0, -1,0,0, -1,0,0, 0,-1,0, 0,-1,0, 0,-1,0, 0,-1,0, 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1, }; GLfloat vert[] = { 1,1,1, -1,1,1, -1,-1,1, 1,-1,1, 1,1,1, 1,-1,1, 1,-1,-1, 1,1,-1, 1,1,1, 1,1,-1, -1,1,-1, -1,1,1, -1,1,1, -1,1,-1, -1,-1,-1, -1,-1,1, -1,-1,-1, 1,-1,-1, 1,-1,1, -1,-1,1, 1,-1,-1, -1,-1,-1, -1,1,-1, 1,1,-1, }; GLuint idxs[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, }; glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); // feed vertices in as texture coordinates glTexCoordPointer(3, GL_FLOAT, 0, vert); glNormalPointer(GL_FLOAT, 0, norm); glVertexPointer(3, GL_FLOAT, 0, vert); glPushMatrix(); glColor4f(1, 1, 1, 1); glScaled(size, size, size); glDrawElements(GL_QUADS, sizeof(idxs)/sizeof(idxs[0]), GL_UNSIGNED_INT, idxs); glPopMatrix(); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); } static GLuint texName; void init(void) { glClearColor(0,0,0,0); // create random texture const int texWidth = 8; const int texHeight = 8; GLubyte tex[texHeight][texWidth][4]; for(int i = 0; i