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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:25:52+00:00 2026-06-03T06:25:52+00:00

the purpose of my program is to load and display a simple cube with

  • 0

the purpose of my program is to load and display a simple cube with the same texture on each face. the problem is the 2 first faces (front, rear) are good. I tried several combinations of vertices in the textures array but it doesn’t work. I don’t know if I need to add more vertices in the textures array or change the order or change the indices array.

#define OFFSET_BUFFER(bytes) ((GLfloat *)NULL + bytes)

float vertices[] =
{
    -1.0f, -1.0f, 1.0f, // 0 
    1.0f, -1.0f, 1.0f,  // 1 
    -1.0f, 1.0f, 1.0f,  // 2 
    1.0f, 1.0f, 1.0f,   // 3 

    -1.0f, -1.0f, -1.0f,// 4 
    1.0f, -1.0f, -1.0f, // 5 
    -1.0f, 1.0f, -1.0f, // 6 
    1.0f, 1.0f, -1.0f,  // 7 
}; 

GLubyte indices[] =
{
    0,1,2, 1,3,2, //front face
    6,7,5, 6,5,4, //rear face
    1,5,3, 5,7,3, //problem on the right face
    //2,3,6, 3,6,7,
    //2,4,0, 2,4,6
    0,5,1, 5,4,0
}; 

float textures[] =
{
    0.0f, 1.0f,//0
    1.0f, 1.0f,//1
    0.0f, 0.0f,//2
    1.0f, 0.0f,//3

    0.0f, 1.0f,//0
    1.0f, 1.0f,//1
    0.0f, 0.0f,//2
    1.0f, 0.0f,//3
}; 

int main(int argc, char *argv[])
{
    SDL_Init(SDL_INIT_VIDEO);
    SDL_WM_SetCaption("Texture Mapping",NULL);
    SDL_SetVideoMode(500, 500, 32, SDL_OPENGL);

    bool continuer = true;
    SDL_Event event;
    GLuint texCube;

    glClearDepth(1.0f);
    glClearColor(0.1f, 0.1f, 0.1f, 0.1f);
    glEnable(GL_DEPTH_TEST);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(70.0f, (float)500.0f / (float)500.0f, 1.0f, 3000.0f);
    glewInit();

    texCube = loadTexture("caisse.jpg");
    glBindTexture(GL_TEXTURE_2D, texCube);

    glEnable(GL_TEXTURE_2D);

    while (continuer)
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        SDL_WaitEvent(&event);
        switch(event.type)
        {
            case SDL_QUIT:
                continuer = false;
        }

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        gluLookAt(0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

        //Draw Cube ---------------------------------------

        glPushMatrix();
        glRotatef(90.0f, 1.0f, 1.0f, 0.0f);

        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointer(3, GL_FLOAT, 0, vertices);

        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glTexCoordPointer(2, GL_FLOAT, 0, textures);

        glDrawElements(GL_TRIANGLES, 24, GL_UNSIGNED_BYTE, indices);

        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);

        //-------------------------------------------------

        glPopMatrix();

        glFlush();
        SDL_GL_SwapBuffers();
    }

    glDisable(GL_TEXTURE_2D);
    SDL_Quit();

    return 0;
}
  • 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-03T06:25:54+00:00Added an answer on June 3, 2026 at 6:25 am

    Your corners are sharing texture coordinates, which just isn’t going to work.
    you should have 4 vertices for each face, as the texture coordinates for each corner will be different depending on the face.

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

Sidebar

Related Questions

I've written several variations of a program. The purpose of the program is to
I have an OCR program, written with C# (WinForms app). So it's main purpose
I try to call the esriRegAsm.exe with arguments from a C# program. The purpose
I am writing a simple keylogger program (for non-malicious purposes). Note: This is with
[purpose] This simple command sequence runs expected in the Windows' CMD shell: dir &
Here's the deal. I've got a program that will load a given assembly, parse
The purpose of my Program is to capture multiple areas on the screen. I'm
the purpose of this activity/program is to simply switch from this activity to another
Does a free general purpose ASN.1 Decode/Dump/Inspect program exist? I have a suspect ASN.1
I am working on a program which includes a general purpose engine, some program

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.