Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9248563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:58:20+00:00 2026-06-18T09:58:20+00:00

I’ve created a plane at OpenGL with this code: glBegin(GL_TRIANGLE_STRIP); glColor4f(0.8, 0.8, 0.5, 1.0);

  • 0

I’ve created a plane at OpenGL with this code:

glBegin(GL_TRIANGLE_STRIP);
glColor4f(0.8, 0.8, 0.5, 1.0);
glVertex3f(startlen, height, startwid);    
glVertex3f(startlen, height, startwid + width);
glVertex3f(startlen + length, height, startwid);
glVertex3f(startlen + length, height, startwid + width);
glEnd();

Now I want to apply a texture to this plane.

I’ve read this tutorial here but I’ve stopped at the “Using the texture in OpenGL” part because I don’t have the UV coordinates.

I know that we have to import the texture file, in my case a bitmap file.
The loader returns a Glint, which is the textureID, is that global? In example, if I need to load that texture I simply need to call the bind texture function with the ID given?

Anyway, how can I apply the texture to the plane?


EDIT #1:
The texture at the example mosquito posted works now.
What I found out was that I was loading the texture into the constructor of the class and I shouldn’t because the object was public and it was constructed before OpenGL’s initialization.
So the texture now loads fine at the quad example 🙂

The problem now is that I’ve tried to use it at my plane and it looks distorted.
The solution to this is probably enabling the texture to be loaded several times but keep it’s original size (although I don’t know how to do this).

Also, I’ve created another plane next to the current one with a cream colour but after the texturing it seems like this:
enter image description here

So there are 2 problems now:

  • texture must keep it’s original resolution but displayed as many times as to cover the whole plane
  • the plane next to it, has lost its colour (why did this happen? How to fix it? — I might use a texture for this plane as well)

Edit #2:

2nd problem has been fixed now, thanks to mosquito!
But the tiling still doesn’t work.
This is how it looks now:
enter image description here

And this is the texture I’ve used:
enter image description here
Its dimensions are 256×256 (I’ve used an image editor to crop it)


Edit #3:
These are the glTexCoord2f coordinates with their matching vertices (for the inner margin):

glTexCoord2f(0.0f, 0.0f);   glVertex3f(startlen, height, startwid);
glTexCoord2f(0.0f, 1.0f);   glVertex3f(startlen, height, startwid - width/2);
glTexCoord2f(1.0f, 0.0f);   glVertex3f(startlen + length, height, startwid);
glTexCoord2f(1.0f, 1.0f);   glVertex3f(startlen + length, height, startwid - width/2);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:58:21+00:00Added an answer on June 18, 2026 at 9:58 am

    If you have loader which returns textureID then it probably already takes care of loading image data, setting properties and storing it as a real texture for further use. So I’ll just move on to binding texture to your texturing target.

    If you have this id, you basically have to call glBindTexture() function before drawing your triangle strip:

    glBindTexture(GL_TEXTURE_2D, id); // where id is GLuint returned by your loader
    

    now for each vertex you draw, you should also specify coordinates of texture for those vertices. To do so, you use glTexCoord2f() function. For simple quad, it could look like this:

    glBegin(GL_QUADS);
        // Bottom left
        glTexCoord2f(0.0f, 1.0f);                   
        glVertex2i(0.0f, 10.0f);
    
        // Top left
        glTexCoord2f(0.0f, 0.0f);
        glVertex2i(0.0f, 0.0f);
    
        // Top right
        glTexCoord2f(1.0f, 0.0f);
        glVertex2i(10.0f, 0.0f);
    
        // Bottom right
        glTexCoord2f(1.0f, 1.0f);
        glVertex2i(10.0f, 10.0f);
    glEnd();
    

    As you can see, each vertex has texture ‘point’ attached to it. It will tell OpenGL how to display your texture.

    Now it’s up to you to choose how you want your texture to be distributed on a plane by specifying proper coordinates for vertices.

    What you have to remember is that texture coordinates starts with 0.0 and ends with 1.0. Increasing this value to more than 1.0 will result in behaviour depending on settings for your texture (e.g. tiling).

    In your tutorial, you have really nice picture presenting that texture coordinates are from 0.0 to 1.0 range and what texture coordinates are being set for specific vertices:

    enter image description here

    PS. In order to make textures being displayed, you have to enable this capability first by calling:

    glEnable(GL_TEXTURE_2D);
    

    You don’t have to call it every time you draw object with texture. It may be called just once before your drawing.


    EDIT

    1. According to your next problem: What you want is to achieve tiling
      effect, which can be easily done during creating a texture.
      In your loader, after this line:

      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

      you should set next texture parameters like this:

      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
      

      In this case GL_REPEAT is being used to repeat texture whenever
      it’s coordinates are higher than 1.0. For example if you specify
      texture coordinate to be 2.0 it is the same as you’d put 1.0, and so
      on.

    2. Your second problem exist because you have still your texture bound
      and you have texturing enabled (remember that you used
      glEnable(GL_TEXTURE_2D);), so basically everything you draw now,
      will be covered with texture.

      However if you want now to draw something without texturing it, you
      basically have to disable texturing before drawing your second plane
      and enable it again after drawing:

      glDisable(GL_TEXTURE_2D);
         // Draw your second plane here
      glEnable(GL_TEXTURE_2D);
      

    EDIT2

    Well, I think you misunderstood me a bit. In this case tiling cannot work, because you specify texture coordinates to maximum of 1.0 which is the end of your texture. I have prepared an image that could show you what I mean:

    enter image description here

    In those pictures in the middle with red color I marked texture coordinates and with black – vertices coordinates.

    So basically if you set your texture coordinates like you do it right now (max of 1.0), you make your texture stretched around your plane. Now imagine that this plane is very large – it can cause nothing else but ugly stretch effect if texture is of low resolution.

    In order to achieve tiling effect, you have to set values higher than 1.0, like in my example – 2.0 causes texture to be repeated two times.

    As there is no magic method to make your texture look ‘nice’ on your plane, you have to use some math to achieve it. Now this I leave to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.