🔒 Locked
OpenGL texturing
Advertisement
Original Post
Well this is some really aweful code....
But here it is, this is pretty well just the draw function
fXoff, fYoff, and uZoom, are used to move and zoom....
The resizer things were put in there so I could mess with the texture coords a little easier
There the code, in source tags... for OpenGLAaron
[Edited by - Arenth on November 26, 2004 5:39:54 PM]
But here it is, this is pretty well just the draw function
fXoff, fYoff, and uZoom, are used to move and zoom....
The resizer things were put in there so I could mess with the texture coords a little easier
static void draw_screen( void ){unsigned long int i;unsigned long int j;float resizerX;float resizerY; glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, gTexture); glMatrixMode( GL_TEXTURE ); glLoadIdentity(); glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); glTranslatef( fXOff, fYOff, uZoom ); glRotatef(180,1,0,0); glBegin( GL_TRIANGLES ); for (i = 0; i<Map.MPolygon_Start.PolyCount; i++) { resizerX = Map.Polygon.Poly.Vertices[2].X; resizerY = Map.Polygon.Poly.Vertices[2].Y; glTexCoord2f(resizerX, resizerY); glColor4ub(Map.Polygon.Poly.Vertices[2].DColorB, Map.Polygon.Poly.Vertices[2].DColorG, Map.Polygon.Poly.Vertices[2].DColorR, Map.Polygon.Poly.Vertices[2].DColorA); glVertex3f(Map.Polygon.Poly.Vertices[2].X, Map.Polygon.Poly.Vertices[2].Y, Map.Polygon.Poly.Vertices[2].Z ); resizerX = Map.Polygon.Poly.Vertices[1].X; resizerY = Map.Polygon.Poly.Vertices[1].Y; glTexCoord2f(resizerX, resizerY); glColor4ub(Map.Polygon.Poly.Vertices[1].DColorB, Map.Polygon.Poly.Vertices[1].DColorG, Map.Polygon.Poly.Vertices[1].DColorR, Map.Polygon.Poly.Vertices[1].DColorA); glVertex3f(Map.Polygon.Poly.Vertices[1].X, Map.Polygon.Poly.Vertices[1].Y, Map.Polygon.Poly.Vertices[1].Z ); resizerX = Map.Polygon.Poly.Vertices[0].X; resizerY = Map.Polygon.Poly.Vertices[0].Y; glTexCoord2f(resizerX, resizerY); glColor4ub(Map.Polygon.Poly.Vertices[0].DColorB, Map.Polygon.Poly.Vertices[0].DColorG, Map.Polygon.Poly.Vertices[0].DColorR, Map.Polygon.Poly.Vertices[0].DColorA); glVertex3f(Map.Polygon.Poly.Vertices[0].X, Map.Polygon.Poly.Vertices[0].Y, Map.Polygon.Poly.Vertices[0].Z); } glEnd( );glDisable(GL_TEXTURE_2D);SDL_GL_SwapBuffers( ); }There the code, in source tags... for OpenGLAaron
[Edited by - Arenth on November 26, 2004 5:39:54 PM]
after a quick gander, your code looks ok
try doing this before you render
try doing this before you render
glMatrixMode( GL_TEXTURE ); glLoadIdentity();glMatrixMode( GL_MODELVIEW );
Try using the glext.h header file. GL_CLAMP_TO_EDGE is an OpenGL 1.2 constant, I believe, and windows only includes OpenGL 1.1. Also, could you include your code in [ source ] tags? Please? For me? :)
Well I tried GL_CLAMP_TO_EDGE and it looks just like GL_CLAMP.
This is what clamped, and clamped to edge both look like:

A whole lot of blah.....
Well this is something I thought i should add... the vertex coords are not in the range of -1.0 to 1.0, some go all the way up to like 200.
Also the glRotatef(180,1,0,0); is there because the vertex coords were for D3D. And they drew upside down, so I flipped the model.
[Edited by - Arenth on November 26, 2004 5:23:20 PM]
This is what clamped, and clamped to edge both look like:

A whole lot of blah.....
Well this is something I thought i should add... the vertex coords are not in the range of -1.0 to 1.0, some go all the way up to like 200.
Also the glRotatef(180,1,0,0); is there because the vertex coords were for D3D. And they drew upside down, so I flipped the model.
[Edited by - Arenth on November 26, 2004 5:23:20 PM]
sorry i meant CLAMP_TO_BORDER which should show a lot of the texture has become black.
anyways the reason it does this is cause the texture coordinates are larger than 1.0 if they are this then the texture tiles , normally u dont use the same numbers for texture coords as u use for vertices (like youre doing)
anyways the reason it does this is cause the texture coordinates are larger than 1.0 if they are this then the texture tiles , normally u dont use the same numbers for texture coords as u use for vertices (like youre doing)
I know you dont usually use the vertex coords for texture coords, but the thing is, i want the program to texture each poly as if they were sort of a mask, like tile the texture over the whole window, and then everywhere that isnt a poly draw black, everywhere that is, draw an undeformed texture.
newbie question guys :
how can i "wrap" an object (made up from vertices from a data file) with a texture, but without providing the texture coordinates (not provided from a data file)? use glTexGen?
and if so how ? in the drawing function what coordinate do i give it ? glTexCoord2f(?,?); ?
I have tried giving it the same with the vertices but no luck.
I have tried providing a set of texture coordinates for each vertice but no luck.
I think that Texture generator is the way to go , but i do not know how to use it.
All in all i'm after an automatic texture generation procedure/tutorial/example.
cheers
P.S. Thanks for your time.
how can i "wrap" an object (made up from vertices from a data file) with a texture, but without providing the texture coordinates (not provided from a data file)? use glTexGen?
and if so how ? in the drawing function what coordinate do i give it ? glTexCoord2f(?,?); ?
I have tried giving it the same with the vertices but no luck.
I have tried providing a set of texture coordinates for each vertice but no luck.
I think that Texture generator is the way to go , but i do not know how to use it.
All in all i'm after an automatic texture generation procedure/tutorial/example.
cheers
P.S. Thanks for your time.
with texgen u dont use texture coordinates, u can set it so it automatically generate texture coordinates depending on where on the screen the vertice is, check out the redbook + the opengl spec etc for info on how to use texture generation (btw u can also do this with a shader without using texture generation)
guys i'm trying to apply a texture to an object consisting of many points. how can I treat this object (that consists of many points) as a whole, as a single unit, so that I can apply a texture to it?
I am loading the object from a data file. So I want something generic thus no usage of specific texture coordinates is possible.
After reading the file for point coordinates , i use this to show the points:
glVertex3f(x, y, z);
I can't use a glTexCoord2f() function to assign texture coordinates because i am after something that will load any object from a file and apply to it a specific texture.
any ideas on how to implement such a thing ? or suggestion for something better?
cheers
I am loading the object from a data file. So I want something generic thus no usage of specific texture coordinates is possible.
After reading the file for point coordinates , i use this to show the points:
glVertex3f(x, y, z);
I can't use a glTexCoord2f() function to assign texture coordinates because i am after something that will load any object from a file and apply to it a specific texture.
any ideas on how to implement such a thing ? or suggestion for something better?
cheers
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement
Zoomed None:
What I want is the texture to stay the same only scaled when I zoom in. What I mean by that is no tileing, only resizeing.