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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:48:18+00:00 2026-05-27T03:48:18+00:00

I am working on a project using the Marching Cubes algorithm and changing the

  • 0

I am working on a project using the Marching Cubes algorithm and changing the data into a 3D model. Now I want to use texture mapping in OpenGL for my 3D model. I have tried a simple example to begin with, which maps a picture onto a triangle.

Here is my code:

int DrawGLScene(GLvoid)    // Here's Where We Do All The Drawing
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
    glLoadIdentity();                            // Reset The Current Matrix
    glTranslatef(1.0f,0.0f,-6.0f);               // Move Into The Screen 5 Units
    glRotatef(xrot,1.0f,0.0f,0.0f);              // Rotate On The X Axis
    glRotatef(yrot,0.0f,1.0f,0.0f);              // Rotate On The Y Axis
    glRotatef(zrot,0.0f,0.0f,1.0f);              // Rotate On The Z Axis
    glBindTexture(GL_TEXTURE_2D, texture[0]);    // Select Our Texture
    glBegin(GL_TRIANGLES);

    glTexCoord2f(0, 0); glVertex3f( -2,  0, -2 );
    glTexCoord2f(1, 0); glVertex3f(  2,  0, -2 );
    glTexCoord2f(0.5, 1); glVertex3f(  0,  2, -2 );

    glEnd();

    xrot+=0.3f;                             // X Axis Rotation
    yrot+=0.2f;                             // Y Axis Rotation
    zrot+=0.4f;                             // Z Axis Rotation
    return true;                            // Keep Going
} 

Now the problem is that the picture does not map completely within the triangle, and the program cut the image for the triangle, so I am losing some part of my data.
How can I map the whole image into the triangle?

  • 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-27T03:48:19+00:00Added an answer on May 27, 2026 at 3:48 am

    If you’re trying to load the entire texture as a rectangle/square, you have to make a square in OpenGL using either a quad or two triangles, and then map half of the texture to each triangle.

    Like this:

    int DrawGLScene(GLvoid)    // Here's Where We Do All The Drawing
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
        glLoadIdentity();                            // Reset The Current Matrix
        glTranslatef(1.0f,0.0f,-6.0f);               // Move Into The Screen 5 Units
        glRotatef(xrot,1.0f,0.0f,0.0f);              // Rotate On The X Axis
        glRotatef(yrot,0.0f,1.0f,0.0f);              // Rotate On The Y Axis
        glRotatef(zrot,0.0f,0.0f,1.0f);              // Rotate On The Z Axis
        glBindTexture(GL_TEXTURE_2D, texture[0]);    // Select Our Texture
        glBegin(GL_TRIANGLES);
    
        // first triangle, bottom left half
        glTexCoord2f(0, 0); glVertex3f( -2,  0, -2 );
        glTexCoord2f(1, 0); glVertex3f(  2,  0, -2 );
        glTexCoord2f(0, 1); glVertex3f( -2,  2, -2 );
    
        // second triangle, top right half
        glTexCoord2f(1, 0); glVertex3f(  2,  0, -2 );
        glTexCoord2f(0, 1); glVertex3f( -2,  2, -2 );
        glTexCoord2f(1, 1); glVertex3f(  2,  2, -2 );
    
        glEnd();
    
        xrot+=0.3f;                             // X Axis Rotation
        yrot+=0.2f;                             // Y Axis Rotation
        zrot+=0.4f;                             // Z Axis Rotation
        return true;                            // Keep Going
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an ASP.NET project using MVP architecture. We would like to use
I'm working on a project using OpenCV on template matching, and I want to
I am working on a project using JavaMail. I want to access my Gmail
The project I'm working is using n-tier architecture. Our layers are as follows: Data
I am working on a school project using Spring MVC (Spring 3.0.0). Now everything
I am working on a project using Visual Studio(c#). I want to create a
I'm working on a project using C++. I want a TimerHandler to be called
I'm working on a project using Apache Tiles 2.1 . I am running into
I'm working on a project using Windows 2008, .NET 3.5 and WCF for some
I am working on a project using rails 2.1.1. With the new release of

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.