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

  • SEARCH
  • Home
  • 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 8883979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:57:08+00:00 2026-06-14T20:57:08+00:00

I have acube and a texture is to be put on all sides. I

  • 0

I have acube and a texture is to be put on all sides.
I did this successfully in a netbeans project, but at the end I got to know that its to be done in eclipse, at first it didn’t sound to be a big deal. But the thing is that same code doesn’t work in eclipse. The cube is shown but texture is not being applied. heres the code.

        public void init(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2(); // Get the GL pipeline object this 
        // GLAutoDrawable uses

        gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set clear color to black
        gl.glClearDepth(1.0f); // Set the depth value to 1.0 (the maximum value),
        // when the depth buffer is cleared

        gl.glEnable(GL_DEPTH_TEST); //Enable depth test

        gl.glEnable(GL_LIGHT0);     
        gl.glEnable(GL_LIGHTING);           


        try {
            texImg = readImage("PWelshDragon.jpg");
        } catch (IOException ex) {
         //   Logger.getLogger(CG0T.class.getName()).log(Level.SEVERE, null, ex);
        }

             gl.glDisable(GL.GL_TEXTURE_2D);
             gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, texWidth ,texHeight, 0, GL.GL_RGB, GL.  GL_UNSIGNED_BYTE,  texImg);
        gl.glEnable(GL.GL_TEXTURE_2D);

    }

In the display code.

public void display(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();

        gl.glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        gl.glMatrixMode(GL_MODELVIEW);
        gl.glLoadIdentity();

        gl.glRotated(30, 1, 1, 1);

        gl.glBegin(GL_QUADS);
            gl.glNormal3f(1.0f, 0.0f, 0.0f);
            gl.glVertex3f(1.0f, 1.0f, 1.0f);gl.glTexCoord2d(0.0f, 0.0f);
            gl.glVertex3f(1.0f, -1.0f, 1.0f);gl.glTexCoord2d(1.0f, 0.0f);
            gl.glVertex3f(1.0f, -1.0f, -1.0f);gl.glTexCoord2d(1.0f, 1.0f);
            gl.glVertex3f(1.0f, 1.0f, -1.0f);gl.glTexCoord2d(0.0f, 1.0f);

            gl.glNormal3f(-1.0f, 0.0f, 0.0f);
            gl.glVertex3f(-1.0f, 1.0f, 1.0f);gl.glTexCoord2d(0.0f, 0.0f);
            gl.glVertex3f(-1.0f, 1.0f, -1.0f);gl.glTexCoord2d(1.0f, 0.0f);
            gl.glVertex3f(-1.0f, -1.0f, -1.0f);gl.glTexCoord2d(1.0f, 1.0f);
            gl.glVertex3f(-1.0f, -1.0f, 1.0f);gl.glTexCoord2d(0.0f, 1.0f);


            gl.glNormal3f(0.0f, 1.0f, 0.0f);
            gl.glVertex3f(1.0f, 1.0f, 1.0f);gl.glTexCoord2d(0.0f, 0.0f);
            gl.glVertex3f(1.0f, 1.0f, -1.0f);gl.glTexCoord2d(1.0f, 0.0f);
            gl.glVertex3f(-1.0f, 1.0f, -1.0f);gl.glTexCoord2d(1.0f, 1.0f);
            gl.glVertex3f(-1.0f, 1.0f, 1.0f);gl.glTexCoord2d(0.0f, 1.0f);

            gl.glNormal3f(0.0f, -1.0f, 0.0f);
            gl.glVertex3f(1.0f, -1.0f, 1.0f);gl.glTexCoord2d(0.0f, 0.0f);
            gl.glVertex3f(-1.0f, -1.0f, 1.0f);gl.glTexCoord2d(1.0f, 0.0f);
            gl.glVertex3f(-1.0f, -1.0f, -1.0f);gl.glTexCoord2d(1.0f, 1.0f);
            gl.glVertex3f(1.0f, -1.0f, -1.0f);gl.glTexCoord2d(0.0f, 1.0f);

            gl.glNormal3f(0.0f, 0.0f, 1.0f);
            gl.glVertex3f(1.0f, 1.0f, 1.0f);gl.glTexCoord2d(0.0f, 0.0f);
            gl.glVertex3f(-1.0f, 1.0f, 1.0f);gl.glTexCoord2d(1.0f, 0.0f);
            gl.glVertex3f(-1.0f, -1.0f, 1.0f);gl.glTexCoord2d(1.0f, 1.0f);
            gl.glVertex3f(1.0f, -1.0f, 1.0f);gl.glTexCoord2d(0.0f, 1.0f );


            gl.glNormal3f(0.0f, 0.0f, -1.0f);
            gl.glVertex3f(1.0f, 1.0f, -1.0f);gl.glTexCoord2d(0.0f, 0.0f);
            gl.glVertex3f(1.0f, -1.0f, -1.0f);gl.glTexCoord2d(1.0f, 0.0f);
            gl.glVertex3f(-1.0f, -1.0f, -1.0f);gl.glTexCoord2d(1.0f, 1.0f);
            gl.glVertex3f(-1.0f, 1.0f, -1.0f);gl.glTexCoord2d(0.0f, 1.0f);
        gl.glEnd();
    }

I’m getting the values in texImg, but dont know why its not being applied.

  • 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-14T20:57:09+00:00Added an answer on June 14, 2026 at 8:57 pm

    I solved the problem, by adding following lines before image drawing code in display function. (before gl.glBegin(GL_QUADS);)

    gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_WRAP_S,GL2.GL_CLAMP);
    gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_WRAP_T,GL2.GL_CLAMP);
    gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MAG_FILTER,GL.GL_NEAREST);
    gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MIN_FILTER,GL.GL_NEAREST);
    gl.glTexEnvi(GL2.GL_TEXTURE_ENV,GL2.GL_TEXTURE_ENV_MODE,GL2.GL_MODULATE);
    gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT,GL2.GL_NICEST);
    

    I don’t really know, what these lines do. I saw it here

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

Sidebar

Related Questions

I have this OBJ file for a cube with texture: # Max2Obj Version 4.0
have written this little class, which generates a UUID every time an object of
I have a texture loader from the asteroids examples for LWJGL. It loads the
i have a question concerning how to declare the points for a texture on
I have a cube with ofcourse 6 sides. Now I want not to render
I have a problem with the rendering of a cube. I don't know why
So I have successfully made a ray the represents the mouse unprojected into the
I have this vertex array of a cube float vertex_coordinates [] = { -12.43796,
I have made a cube with a texture and text on it. When I
I have a cube map texture in OpenGL, and I'd like to render one

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.