• Advertisement
Sign in to follow this  

OPenGL:texture mapping problem

This topic is 651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi

 

I am trying to render a sprite on a png file.  some of the sizes of some sprite are small and some are bigger.

 

suppose i have the following codes in a rendering function

 

glBindTexture(GL_TEXTURE_2D, id);
...
glTexCoord2d(0.3, 0.6); glVertex2d(70, 100);
glTexCoord2d(0.3, 0.3);   glVertex2d(70, 50);
glTexCoord2d(0.4, 0.3);   glVertex2d(200, 50);
glTexCoord2d(0.4, 0.6); glVertex2d(200, 100);
 
and 
 
glBindTexture(GL_TEXTURE_2D, id);
...
glTexCoord2d(0.3, 0.9); glVertex2d(70, 100);
glTexCoord2d(0.3, 0.6);   glVertex2d(70, 50);
glTexCoord2d(0.7, 0.6);   glVertex2d(400, 50);
glTexCoord2d(0.7, 0.9); glVertex2d(400, 100);
 
after the execution of second set of codes, will the image be larger?
 
if it even be possible to do that to a same texture?  on the screen, what i actually see is the same size as the first patch of codes.
 
thanks in advance.
 

 

Share this post


Link to post
Share on other sites
Advertisement

I am not very familiar with OpenGL, but if it is anything like DirectX(which it is), you are adjusting the UV coordinates(or Texture Coordinates in OpenGL I guess). This has nothing to do with the size of your image, although I am not sure exactly what you mean given the context of the question. The second set of code will simply pull more texels from your texture to apply to the vertex information. This does not change the resulting size of your mesh or sprite.

 

Edit:

 

Refer to the attached image. Suppose you have this sweet ground texture. Your first block references a smaller portion of the texture to pull texels from. Your second block of code refers to a larger portion of texture to pull texels from.

Edited by ExErvus

Share this post


Link to post
Share on other sites
The OP is adjusting both the texture coordinates and the vertex positions. Assuming the projection is unchanged a larger section of the texture is rendered to a larger section of the screen.

No one cares how often you render from the same texture to how many primitives, whether it's always the same piece of the texture or not.

I would also like to point out that you are using the extremely deprecated API of OpenGL. I can only strictly advise against learning that. It is very far from how a modern API works and skills you gain in the deprecated API will require some unlearning.

Share this post


Link to post
Share on other sites

The OP is adjusting both the texture coordinates and the vertex positions. Assuming the projection is unchanged a larger section of the texture is rendered to a larger section of the screen.

No one cares how often you render from the same texture to how many primitives, whether it's always the same piece of the texture or not.

I would also like to point out that you are using the extremely deprecated API of OpenGL. I can only strictly advise against learning that. It is very far from how a modern API works and skills you gain in the deprecated API will require some unlearning.

Hi

 

if the functions are deprecated, which functions should i use?  can you give me names or ideas which i can google?

 

thank for your reply.

Share this post


Link to post
Share on other sites

 

The OP is adjusting both the texture coordinates and the vertex positions. Assuming the projection is unchanged a larger section of the texture is rendered to a larger section of the screen.

No one cares how often you render from the same texture to how many primitives, whether it's always the same piece of the texture or not.

I would also like to point out that you are using the extremely deprecated API of OpenGL. I can only strictly advise against learning that. It is very far from how a modern API works and skills you gain in the deprecated API will require some unlearning.

Hi

 

if the functions are deprecated, which functions should i use?  can you give me names or ideas which i can google?

 

thank for your reply.

 

 

You should switch to OpenGL 3.2 or above. I believe that is the version where the things you are using no longer exist (unless you are doing mobile that is). There is no glTexCoord2d or glVertex2d from there on (amongst a fair few other things that you are probably using). It certainly is a lot more difficult to get going but I agree with BitMaster in that I think it is worth you doing. It's hard enough to learn something and right now you are learning something that won't be of much use so it's better to put that effort into something that will have more use. 

 

You can probably stick with the version you are currently using and use the more modern approach, a term you might want to take a look at is 'vertex arrays'.

Edited by Nanoha

Share this post


Link to post
Share on other sites

(unless you are doing mobile that is).


OpenGL ES never had the deprecated stuff. Learning OpenGL ES is actually a very decent alternative to desktop GL, in a lot of ways the API is cleaner and without the historical baggage of desktop GL. I would not actually advise anyone to start learning to program on mobile platforms though.

Share this post


Link to post
Share on other sites

Hi

 

I found my problem.  Apparently, it is not about the functions, I just display the wrong button.

 

but i still want to know a new way to apply the modern API.  so, please response about that.

 

I used VS 2015 on windows 10 OS.

 

thanks

Edited by nickme

Share this post


Link to post
Share on other sites

glBegin()/glEnd() and other immediate function have been deprecated in OpenGL3.0 (2008) and finally disappeared in 3.1 (2009) although they've been on the way out since 2006 with end of GL 2.x ;) So yes, those functions are not in use anymore in modern OpenGL.

 

More modern approach uses VBO ( Vertex Buffer Object ), EBO ( Element Buffer Object ), shaders and lot lot more. There are thousands of tutorials on the Internet and probably you can find some articles here, on gamedev.

Share this post


Link to post
Share on other sites

I'm glad you could fix your issue.

 

If you are interested in the modern OpenGL api, you can use this tutorial to learn the api:

http://www.mbsoftworks.sk/index.php?page=tutorials&series=1

 

There are things that are supported in previous openGL version only through extensions, which are now core features of the openGL api.

+ If you are really interested, there's even a newer api called Vulkan. However, it is far more complicated.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement