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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:21:21+00:00 2026-05-11T14:21:21+00:00

Currently, I’m able to load in a static sized texture which I have created.

  • 0

Currently, I’m able to load in a static sized texture which I have created. In this case it’s 512 x 512.

This code is from the header:

#define TEXTURE_WIDTH 512 #define TEXTURE_HEIGHT 512  GLubyte textureArray[TEXTURE_HEIGHT][TEXTURE_WIDTH][4]; 

Here’s the usage of glTexImage2D:

glTexImage2D(     GL_TEXTURE_2D, 0, GL_RGBA,     TEXTURE_WIDTH, TEXTURE_HEIGHT,     0, GL_RGBA, GL_UNSIGNED_BYTE, textureArray); 

And here’s how I’m populating the array (rough example, not exact copy from my code):

for (int i = 0; i < getTexturePixelCount(); i++) {     textureArray[column][row][0] = (GLubyte)pixelValue1;     textureArray[column][row][1] = (GLubyte)pixelValue2;     textureArray[column][row][2] = (GLubyte)pixelValue3;     textureArray[column][row][3] = (GLubyte)pixelValue4; } 

How do I change that so that there’s no need for TEXTURE_WIDTH and TEXTURE_HEIGHT? Perhaps I could use a pointer style array and dynamically allocate the memory…

Edit:

I think I see the problem, in C++ it can’t really be done. The work around as pointed out by Budric is to use a single dimensional array but use all 3 dimensions multiplied to represent what would be the indexes:

GLbyte *array = new GLbyte[xMax * yMax * zMax]; 

And to access, for example x/y/z of 1/2/3, you’d need to do:

GLbyte byte = array[1 * 2 * 3]; 

However, the problem is, I don’t think the glTexImage2D function supports this. Can anyone think of a workaround that would work with this OpenGL function?

Edit 2:

Attention OpenGL developers, this can be overcome by using a single dimensional array of pixels…

[0]: column 0 > [1]: row 0 > [2]: channel 0 … n > [n]: row 1 … n > [n]: column 1 .. n

… no need to use a 3 dimensional array. In this case I’ve had to use this work around as 3 dimensional arrays are apparently not strictly possible in C++.

  • 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. 2026-05-11T14:21:22+00:00Added an answer on May 11, 2026 at 2:21 pm

    You can use

    int width = 1024; int height = 1024; GLubyte * texture = new GLubyte[4*width*height]; ... glTexImage2D(     GL_TEXTURE_2D, 0, GL_RGBA,     width, height,     0, GL_RGBA, GL_UNSIGNED_BYTE, textureArray); delete [] texture;         //remove the un-needed local copy of the texture; 

    However you still need to specify the width and height to OpenGL in glTexImage2D call. This call copies texture data and that data is managed by OpenGL. You can delete, resize, change your original texture array all you want and it won’t make a different to the texture you specified to OpenGL.

    Edit: C/C++ deals with only 1 dimensional arrays. The fact that you can do texture[a][b] is hidden and converted by the compiler at compile time. The compiler must know the number of columns and will do texture[a*cols + b].

    Use a class to hide the allocation, access to the texture.

    For academic purposes, if you really want dynamic multi dimensional arrays the following should work:

    int rows = 16, cols = 16; char * storage = new char[rows * cols]; char ** accessor2D = new char *[rows]; for (int i = 0; i < rows; i++) {     accessor2D[i] = storage + i*cols; } accessor2D[5][5] = 2; assert(storage[5*cols + 5] == accessor2D[5][5]); delete [] accessor2D; delete [] storage; 

    Notice that in all the cases I’m using 1D arrays. They are just arrays of pointers, and array of pointers to pointers. There’s memory overhead to this. Also this is done for 2D array without colour components. For 3D dereferencing this gets really messy. Don’t use this in your code.

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

Sidebar

Ask A Question

Stats

  • Questions 89k
  • Answers 89k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I highly recommend checking out this thread for various pain… May 11, 2026 at 5:50 pm
  • Editorial Team
    Editorial Team added an answer This is true not only when writing to files, but… May 11, 2026 at 5:50 pm
  • Editorial Team
    Editorial Team added an answer One more try: Have a look at http://msdn.microsoft.com/en-us/library/system.security.principal.windowsbuiltinrole.aspx .... and… May 11, 2026 at 5:50 pm

Related Questions

I am currently running into a problem where an element is coming back from
Currently, I don't really have a good method of debugging JavaScript in Internet Explorer and
Currently, I am writing up a bit of a product-based CMS as my first
Currently, I am developing a product that does fairly intensive calculations using MS SQL
Currently, I have some basic code to play a simple tone whenever a button

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.