Skip to main content
gamedev.net
🔒 Locked

OpenGL texturing

Started by Arenth 20 replies 2.3k views
Original Post
Arenth
Arenth
The problem I'm having is when I zoom into my model the texture doesnt scale with it, it sort of tiles... Zoomed just a little: 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.
Arenth
Arenth
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
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]
silvermace
silvermace
after a quick gander, your code looks ok

try doing this before you render
glMatrixMode( GL_TEXTURE );  glLoadIdentity();glMatrixMode( GL_MODELVIEW );
Arenth
Arenth
Well I tried that, I pasted it right in before where I swapped buffers, and it still does the same thing.
Arenth
Arenth
When I try to use GL_CLAMP_TO_EDGE, it says its undeclared.
OpenGLAaron
OpenGLAaron
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? :)
Arenth
Arenth
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]
zedzeek
zedzeek
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)
Arenth
Arenth
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.
zedzeek
zedzeek
if im guessing right what u want to do a better way is clear the screen to black. enable automatic texture coordinate generation (thus u dont use glTexCoord..(..) ) and then draw the polygons for texgen i think u need GL_EYE_LINEAR (or is that perhaps OBJECT LINEAR)
cockney
cockney
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.
zedzeek
zedzeek
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)
sand_man
sand_man
Dont hijack threads
Start your own
zedzeek
zedzeek
there will be some shader stuff here

http://www.humus.ca/
http://www.delphi3d.net/
http://www.gametutorials.com/
http://www.ultimategameprogramming.com/
http://developer.nvidia.com/page/home
cockney
cockney
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
cockney
cockney
Hi again, it seems noone is willing to answer my questions.

Is anyone familiar with a program that will export coordinates to TXT file? can anyone suggest any?

cheers

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.