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 7493623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:05:28+00:00 2026-05-29T17:05:28+00:00

I’m having an issue with texture mapping in OpenGL. I’m attempting to apply different

  • 0

I’m having an issue with texture mapping in OpenGL. I’m attempting to apply different textures to different objects in the scene, but I’m finding that applying a second texture to a second object is changing the texture coordinates (I think) on the first one. The two objects are a cube and a cylinder.

With only one texture enabled, the scene looks like this:
enter image description here

If I then enable textures for 1 or more other objects, I see this (I’m not too bothered about the bad texture mapping on the “wheels” right now):
enter image description here

What could be causing this? My drawing code for the cube and cylinders is below:

Cube:

    //Alias the values for easier reading
double X = Position().X;
double Y = Position().Y;
double Z = Position().Z;
double W = _fWidth;
double H = _fHeight;
double D = _fDepth;

//Set textures if necessary
if(super._blHasTexture)
{
    super._obTexture.bind(gl);
}

_obTexture.enable(gl);
gl.glColor3f(0.5f, 0.5f, 0.7f);
//Draw

    gl.glBegin(GL2.GL_QUADS);
        //Front
    gl.glNormal3f(0f, 0f, 1f);
    gl.glVertex3d(X, Y, Z);     gl.glTexCoord2f(0f, 0f);
    gl.glVertex3d(X+W, Y, Z);   gl.glTexCoord2f(1f, 0f);
    gl.glVertex3d(X+W, Y-H, Z); gl.glTexCoord2f(1f, 1f);
    gl.glVertex3d(X, Y-H, Z);   gl.glTexCoord2f(0f, 1f);

    //Back
    gl.glNormal3f(0f, 0f, -1f);
    gl.glVertex3d(X, Y, Z-D);   gl.glTexCoord2f(0f, 0f);
    gl.glVertex3d(X+W, Y, Z-D); gl.glTexCoord2f(1f, 0f);
    gl.glVertex3d(X+W, Y-H, Z-D); gl.glTexCoord2f(1f, 1f);
    gl.glVertex3d(X, Y-H, Z-D); gl.glTexCoord2f(0f, 1f);

    //Left
    gl.glNormal3f(-1f, 0f, 0f);
    gl.glVertex3d(X, Y, Z);     gl.glTexCoord2f(0f, 0f);
    gl.glVertex3d(X, Y, Z-D);   gl.glTexCoord2f(1f, 0f);
    gl.glVertex3d(X, Y-H, Z-D); gl.glTexCoord2f(1f, 1f);
    gl.glVertex3d(X, Y-H, Z);   gl.glTexCoord2f(0f, 1f);            

    //Right
    gl.glNormal3f(1f, 0f, 0f);
    gl.glVertex3d(X+W, Y, Z);   gl.glTexCoord2f(0f, 0f);
    gl.glVertex3d(X+W, Y, Z-D); gl.glTexCoord2f(1f, 0f);
    gl.glVertex3d(X+W, Y-H, Z-D); gl.glTexCoord2f(1f, 1f);
    gl.glVertex3d(X+W, Y-H, Z); gl.glTexCoord2f(0f, 1f);

    //Top
    gl.glNormal3f(0f, 1f, 0f);
    gl.glVertex3d(X, Y, Z);     gl.glTexCoord2f(0f, 0f);
    gl.glVertex3d(X+W, Y, Z);   gl.glTexCoord2f(1f, 0f);
    gl.glVertex3d(X+W, Y, Z-D); gl.glTexCoord2f(1f, 1f);
    gl.glVertex3d(X, Y, Z-D);   gl.glTexCoord2f(0f, 1f);

    //Bottom
    gl.glNormal3f(0f, -1f, 0f);
    gl.glVertex3d(X, Y-H, Z);   gl.glTexCoord2f(0f, 0f);
    gl.glVertex3d(X+W, Y-H, Z); gl.glTexCoord2f(1f, 0f);
    gl.glVertex3d(X+W, Y-H, Z-D); gl.glTexCoord2f(1f, 1f);
    gl.glVertex3d(X, Y-H, Z-D); gl.glTexCoord2f(0f, 1f);
gl.glEnd();

_obTexture.disable(gl);

Cylinder:

GLUquadric quad = glu.gluNewQuadric();
glu.gluQuadricTexture(quad, true);  

_obTexture.bind(gl);
_obTexture.enable(gl);

    //Draw the caps
gl.glBegin(GL2.GL_TRIANGLE_FAN);
    gl.glVertex3f(0f, 0f, 0.01f);
    gl.glTexCoord2f(0f, 0f);
    for(int t = 0; t < 20; t++)
    {
        float X = _fRadius * (float)Math.cos(t);
        float Y = _fRadius * (float)Math.sin(t);
        gl.glVertex3f(X, Y, 0.01f);
    }
    gl.glTexCoord2f(1f, 1f);
gl.glEnd();

gl.glBegin(GL2.GL_TRIANGLE_FAN);
    gl.glVertex3f(0f, 0f, -0.01f + _fHeight);
    gl.glTexCoord2f(0f, 0f);
    for(int t = 0; t < 20; t++)
    {
        float X = _fRadius * (float)Math.cos(t);
        float Y = _fRadius * (float)Math.sin(t);
        gl.glVertex3f(X, Y, -0.01f + _fHeight);
    }
        gl.glTexCoord2f(1f, 1f);
gl.glEnd();         

glu.gluCylinder(quad, _fRadius, _fRadius, _fHeight, 20, 1);
_obTexture.disable(gl);
  • 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-05-29T17:05:32+00:00Added an answer on May 29, 2026 at 5:05 pm

    Assign your texture coordinates BEFORE each call to glVertex, not after – calls after that apply to the following glVertex call.

    The way you are doing it, the last coordinate set is being applied to the first vertex (i.e. a corner of your cube) in the next render cycle – hence the difference when you render additional objects.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but

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.