• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# OpenGL texture mapping using OpenGL

## Recommended Posts

hi there... I have a problem where I created a 3d object using glBegin(GL_LINES) and using glVertex3f() to specify the points. So, the 3d wireframe is ok. But when I try to put some texture on it, by using glBindTexture, etc, I still get a wireframe model but the wireframe itself are textured! I don''t want a wireframe anymore, I want a solid model (textured of course). Where am I going wrong? Xtreme.

##### Share on other sites
Try using GL_TRIANGLES to draw your models. GL_LINES, as the name suggests, will only draw lines.

##### Share on other sites
THANKS! that worked

BUT!

if I don''t texture it, i get multiple lines instead of the required ones. How can I get rid of the extra lines used to make up the mesh?

##### Share on other sites
Could be due to previously using GL_LINES instead of GL_TRIANGLES. You might be trying to draw much more than neccessary but still getting the same effect when textured.

##### Share on other sites
actually quite the opposite! I can see that more (unnecessary) lines are drawn with GL_TRIANGLES. but its ok with GL_LINES.
But, when I decide to put a texture on it, the one with GL_TRIANGLES comes out solid while the one with GL_LINES is textured in wireframe only.

Also, how can I divide up the textures in the whole 3d wireframe so that I can have I have say one texture on the body, a different one on the arms, etc... (that is, having multiple textures on the one object?) Currently, this texture is mapping to every single part of the object!

##### Share on other sites
currently this is how I implemented it:

  glEnable(GL_TEXTURE_2D);//glEnable(GL_BLEND);glBindTexture(GL_TEXTURE_2D, texId[2]);glEnable(GL_TEXTURE_GEN_S);glEnable(GL_TEXTURE_GEN_T);glTexGenf(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);glTexGenf(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);glBegin(GL_TRIANGLES);//draw object using glVertex3f() onlyglEnd();glDisable(GL_TEXTURE_GEN_S);glDisable(GL_TEXTURE_GEN_T);glDisable(GL_TEXTURE_2D);//glDisable(GL_BLEND);

Now, with this, I get one texture mapped to all of the object, how can I divide it up?

##### Share on other sites
i dont really understand what u want to do
do u want to draw the solid model textured
and then afterwards draw a wireframe version of the model over the top of it so u can see the individual tris of the solid model.

http://members.xoom.com/myBollux

##### Share on other sites
zeedzeek, i don''t want a wireframe model. (i just did that to see if the lines were drawn right).

I want a solid model but since I made this model from one piece (that is, from glvertex3fs) I now want parts of the object to be texture mapped with not just one, but multiple textures.

Is that possible?

##### Share on other sites
to use multiple textures u have to break your model(mesh) up into multiple meshes cause u cant go
glBegin(GL_TRIANGLES)
vertex,vertex,vertex etc
bind another texture
vertex,vertex,vertex etc
bind another texture
vertex,vertex,vertex etc
glEnd( );

http://members.xoom.com/myBollux

##### Share on other sites
so in other words, you are saying to attach a separate texture, i must use glBegin() and glEnd() separately? which means I have to break up the object into several objects?

##### Share on other sites
OpenGL is based on triangles not mesh, so yes.

Maybe you should read the OpenGL doc, cause it''s explains how OpenGL works...

There''s a link to an electronic version of the Red book on nehe.gamedev.net

-* So many things to do, so little time to spend. *-

##### Share on other sites
you can also use squares (GL_QUADS)instead of triangles. sometimes they''re even more useful

##### Share on other sites
Guys... I never thought about this before, because I''ve never had a reason to try it. Is it possible to bind multiple textures to one polygon by specifying mapping coordinates? As an example, could I map a quad with 4 seperate textures on each "corner"?

##### Share on other sites
probably yes. but watch out for textures width&height because if textures are too big there is VERY big chance that the program will report error.but why don''t you use 4 quads instead of just 1? you must just be careful at coordinates!!!

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627664
• Total Posts
2978522
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 10
• 10
• 12
• 22
• 13