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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:48:11+00:00 2026-05-23T23:48:11+00:00

Edit: Okay, this code still doesn’t allow me to use two different textures in

  • 0

Edit: Okay, this code still doesn’t allow me to use two different textures in the program. It acts like it should work, but when I tell it to use the first texture, it’s the same as the second texture, which is the last texture that’s loaded.

        private int[] iTextures = new int[3];

        public void main()
        {
            Initialize();
            LoadContent();

            float Time = 0.0F;

            // Start game loop
            while (App.IsOpened())
            {
                // Process events
                App.DispatchEvents();

                // Clear the window
                App.Clear();

                App.Draw(Background);

                Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT);

                // Transformations
                Time += App.GetFrameTime();
                Gl.glMatrixMode(Gl.GL_MODELVIEW);
                Gl.glLoadIdentity();
                Gl.glTranslatef(0.0F, 0.0F, -200.0F);


                Gl.glPushMatrix();

                Gl.glScalef(10.0f, 50.0f, 10.0f);
                DrawCube(50.0f, 50.0f, 50.0f, 0);

                Gl.glPopMatrix();

                //Gl.glRotatef(Time * 50, 1.0F, 0.0F, 0.0F);
                //Gl.glRotatef(Time * 30, 0.0F, 1.0F, 0.0F);
                //Gl.glRotatef(Time * 90, 0.0F, 0.0F, 1.0F);


                /*Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
                Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, 50.0F, -50.0F);
                Gl.glTexCoord2f(1, 1); Gl.glVertex3f(50.0F, 50.0F, -50.0F);
                Gl.glTexCoord2f(1, 0); Gl.glVertex3f(50.0F, -50.0F, -50.0F);

                Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, 50.0F);
                Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, 50.0F, 50.0F);
                Gl.glTexCoord2f(1, 1); Gl.glVertex3f(50.0F, 50.0F, 50.0F);
                Gl.glTexCoord2f(1, 0); Gl.glVertex3f(50.0F, -50.0F, 50.0F);

                Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
                Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, 50.0F, -50.0F);
                Gl.glTexCoord2f(1, 1); Gl.glVertex3f(-50.0F, 50.0F, 50.0F);
                Gl.glTexCoord2f(1, 0); Gl.glVertex3f(-50.0F, -50.0F, 50.0F);

                Gl.glTexCoord2f(0, 0); Gl.glVertex3f(50.0F, -50.0F, -50.0F);
                Gl.glTexCoord2f(0, 1); Gl.glVertex3f(50.0F, 50.0F, -50.0F);
                Gl.glTexCoord2f(1, 1); Gl.glVertex3f(50.0F, 50.0F, 50.0F);
                Gl.glTexCoord2f(1, 0); Gl.glVertex3f(50.0F, -50.0F, 50.0F);

                Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, -50.0F, 50.0F);
                Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
                Gl.glTexCoord2f(1, 0); Gl.glVertex3f(50.0F, -50.0F, -50.0F);
                Gl.glTexCoord2f(1, 1); Gl.glVertex3f(50.0F, -50.0F, 50.0F);

                Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, 50.0F, 50.0F);
                Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, 50.0F, -50.0F);
                Gl.glTexCoord2f(1, 0); Gl.glVertex3f(50.0F, 50.0F, -50.0F);
                Gl.glTexCoord2f(1, 1); Gl.glVertex3f(50.0F, 50.0F, 50.0F);


                Gl.glVertex3f(50.0f, 50.0f, 50.0f);
                Gl.glVertex3f(50.0f, 0.0f, 50.0f);
                Gl.glVertex3f(0.0f, 0.0f, 50.0f);
                Gl.glVertex3f(0.0f, 50.0f, 50.0f);

                Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, 10.0F, 50.0F);
                Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, 10.0F, -50.0F);
                Gl.glTexCoord2f(1, 0); Gl.glVertex3f(50.0F, 10.0F, -50.0F);
                Gl.glTexCoord2f(1, 1); Gl.glVertex3f(50.0F, 10.0F, 50.0F);

                Gl.glEnd();*/



                Draw();

                // Finally, display the rendered frame on screen
                App.Display();

            }
            // Don't forget to destroy our texture
            int tex = 0;
            Gl.glDeleteTextures(1, ref tex);
        }

        public void Initialize()
        {
            // Create main window

            App.PreserveOpenGLStates(true);

            // Setup event handlers
            App.Closed += new EventHandler(OnClosed);
            App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            App.Resized += new EventHandler<SizeEventArgs>(OnResized);
        }

        private void LoadContent()
        {
            BackgroundImage = new Image("background.jpg");
            Background = new Sprite(BackgroundImage);

            Text = new String2D("This is a cube");
            Text.Position = new Vector2(0, 0);
            Text.Color = Color.Black;

            // Enable Z-buffer read and write
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthMask(Gl.GL_TRUE);
            Gl.glClearDepth(1.0F);

            // Setup a perspective projection

            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F); // I assume this is setting up the camera

            LoadTexture(new Image("texture.jpg"), 0);

            LoadTexture(new Image("Otexture.jpg"), 1);


        }

        private void Draw()
        {
            App.Draw(Text);
        }

        private void LoadTexture(Image Texture, int texNum)
        {

            using (Image TempImage = Texture)
            {

                Gl.glGenTextures(1, out iTextures[texNum]); // Texture name, which is a number

                Gl.glBindTexture(Gl.GL_TEXTURE_2D, iTextures[texNum]); // Start using the texture


                Console.WriteLine(texNum + "");
                // Texture options and filters and stuff
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_LINEAR);

                Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGBA, (int)TempImage.Width, (int)TempImage.Height, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, TempImage.Pixels);
                //Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA, (int)TempImage.Width, (int)TempImage.Height, 0, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, TempImage.Pixels);

            }
            Gl.glEnable(Gl.GL_TEXTURE_2D);
        }
        private void UseTexture(int iTexture)
        {


            // Bind our texture for use
            //Gl.glEnable(Gl.GL_TEXTURE_2D); // Start using the 2D texture
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, iTexture); // Bind our texture for current use
            Gl.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); // Set color to..white, I think.
        }



        void DrawCube(float xPos, float yPos, float zPos, int texture)
        {

            Gl.glPushMatrix();

            //UseTexture(1);
            Gl.glBegin(Gl.GL_QUADS);
            UseTexture(iTextures[0]);
            //Gl.glEnable(Gl.GL_TEXTURE_2D);



            /*      This is the top face*/
            Gl.glVertex3f(0.0f, 0.0f, 0.0f);
            Gl.glVertex3f(0.0f, 0.0f, -1.0f);
            Gl.glVertex3f(-1.0f, 0.0f, -1.0f);
            Gl.glVertex3f(-1.0f, 0.0f, 0.0f);

            /*      This is the front face*/
            Gl.glTexCoord2f(0, 1); Gl.glVertex3f(0.0f, 0.0f, 0.0f);
            Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-1.0f, 0.0f, 0.0f);
            Gl.glTexCoord2f(1, 0); Gl.glVertex3f(-1.0f, -1.0f, 0.0f);
            Gl.glTexCoord2f(1, 1); Gl.glVertex3f(0.0f, -1.0f, 0.0f);

            /*      This is the right face*/
            Gl.glVertex3f(0.0f, 0.0f, 0.0f);
            Gl.glVertex3f(0.0f, -1.0f, 0.0f);
            Gl.glVertex3f(0.0f, -1.0f, -1.0f);
            Gl.glVertex3f(0.0f, 0.0f, -1.0f);

            /*      This is the left face*/
            Gl.glVertex3f(-1.0f, 0.0f, 0.0f);
            Gl.glVertex3f(-1.0f, 0.0f, -1.0f);
            Gl.glVertex3f(-1.0f, -1.0f, -1.0f);
            Gl.glVertex3f(-1.0f, -1.0f, 0.0f);

            /*      This is the bottom face*/
            Gl.glVertex3f(0.0f, 0.0f, 0.0f);
            Gl.glVertex3f(0.0f, -1.0f, -1.0f);
            Gl.glVertex3f(-1.0f, -1.0f, -1.0f);
            Gl.glVertex3f(-1.0f, -1.0f, 0.0f);

            /*      This is the back face*/
            Gl.glVertex3f(0.0f, 0.0f, 0.0f);
            Gl.glVertex3f(-1.0f, 0.0f, -1.0f);
            Gl.glVertex3f(-1.0f, -1.0f, -1.0f);
            Gl.glVertex3f(0.0f, -1.0f, -1.0f);

            Gl.glEnd();
            Gl.glPopMatrix();
        }

Any help would be awesome.

  • 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-23T23:48:13+00:00Added an answer on May 23, 2026 at 11:48 pm

    You’re not talking about multitexturing; you’re talking about using multiple textures in the same application.

    Well, I see several problems.

    Gl.glGenTextures(2, out iTexture); // Texture name, which is a number
    

    I admit that I’m not 100% familiar with C#’s syntax, so I’m assuming that the out works rather like passing a pointer in C/C++. So you expect glGenTextures to write the texture object number to iTexture.

    There are two problems here. First, iTexture is a single integer. But you told glGenTextures that you were generating two textures in this function call, not one. That would require passing an array of integers for glGenTextures to write into. So you’re risking trashing the… stack? I have no idea how you’re marshalling these calls to C++, but however you’re doing it, glGenTextures is likely writing over random memory. You were lucky not to get a crash.

    Each call to LoadTexture is supposed to create a single OpenGL texture object. Therefore, you should not be trying to create two from a single LoadTexture call.

    The other problem is that iTexture is not returned from your LoadTexture function. You don’t store it anywhere. Indeed, when you call LoadTexture, you don’t even give it an output variable; you give it a number literal. Again, I’m not a C# expert, but I’m pretty sure you would need some special syntax to use an argument as a function output, particularly for a basic type like int.

    Your LoadTexture function should return the OpenGL texture names (or store them somewhere), and the matching UseTexture calls should get those particular names from them.


    New code problems:

    // Don't forget to destroy our texture
    int tex = 0;
    Gl.glDeleteTextures(1, ref tex);
    

    You cannot delete texture 0. That’s generally why people don’t use texture 0 to store actual textures in; it is generally treated as a “texture that doesn’t exist”, like NULL.

    As to your actual drawing code:

    Gl.glBegin(Gl.GL_QUADS);
    UseTexture(iTextures[0]);
    

    You cannot call glBindTexture (or most OpenGL functions) between glBegin/glEnd calls. UseTexture should be called before beginning the quad. Also, UseTexture should enable GL_TEXTURE_2D. I know you use it elsewhere, but it’s best to put commands where they actually matter. And you have to disable GL_TEXTURE_2D if you want to do untextured rendering.

    Also, what do you expect to happen when you only give one quad texture coordinates? What do you expect the other quads to look like? Because if you think that those quads will be untextures, you’re wrong.

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

Sidebar

Related Questions

Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
Edit: I have solved this by myself. See my answer below I have set
I have this code, and for some reason my $.post function fires twice in
Okay. Here's the code. XML Parsing Error: not well-formed <item_to_page_title><![CDATA[Breaking news, real-time scores and
Okay still fighting with doing some SqlCacheDependecy in my Asp.net MVC application I got
Okay so i have a semi weridish problem with re.sub. Take the following code:
Okay, weird situation: I need to Debug a VSTO Office Addin. This was written

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.