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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:31:30+00:00 2026-05-10T18:31:30+00:00

I have image data and i want to get a sub image of that

  • 0

I have image data and i want to get a sub image of that to use as an opengl texture.

glGenTextures(1, &m_name); glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldName); glBindTexture(GL_TEXTURE_2D, m_name); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_data); 

How can i get a sub image of that image loaded as a texture. I think it has something to do with using glTexSubImage2D, but i have no clue how to use it to create a new texture that i can load. Calling:

glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, xWidth, yHeight, GL_RGBA, GL_UNSIGNED_BYTE, m_data); 

does nothing that i can see, and calling glCopyTexSubImage2D just takes part of my framebuffer. Thanks

  • 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-10T18:31:30+00:00Added an answer on May 10, 2026 at 6:31 pm

    Edit: Use glPixelStorei. You use it to set GL_UNPACK_ROW_LENGTH to the width (in pixels) of the entire image. Then you call glTexImage2D (or whatever), passing it a pointer to the first pixel of the subimage and the width and height of the subimage.

    Don’t forget to restore GL_UNPACK_ROW_LENGTH to 0 when you’re finished with it.

    Ie:

    glPixelStorei( GL_UNPACK_ROW_LENGTH, img_width ); char *subimg = (char*)m_data + (sub_x + sub_y*img_width)*4; glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, sub_width, sub_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, subimg ); glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); 

    Or, if you’re allergic to pointer maths:

    glPixelStorei( GL_UNPACK_ROW_LENGTH, img_width ); glPixelStorei( GL_UNPACK_SKIP_PIXELS, sub_x ); glPixelStorei( GL_UNPACK_SKIP_ROWS, sub_y );  glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, sub_width, sub_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_data );  glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 ); glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 ); 

    Edit2: For the sake of completeness, I should point out that if you’re using OpenGL-ES then you don’t get GL_UNPACK_ROW_LENGTH. In which case, you could either (a) extract the subimage into a new buffer yourself, or (b)…

    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, sub_width, sub_height, 0, GL_RGBA, GL_UNSIGNED_BYTES, NULL );  for( int y = 0; y < sub_height; y++ ) {     char *row = m_data + ((y + sub_y)*img_width + sub_x) * 4;     glTexSubImage2D( GL_TEXTURE_2D, 0, 0, y, sub_width, 1, GL_RGBA, GL_UNSIGNED_BYTE, row ); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 59k
  • Answers 59k
  • 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
  • added an answer If security of the files is not an issue you… May 11, 2026 at 9:00 am
  • added an answer The usual way is by writing extension methods to HtmlHelper… May 11, 2026 at 9:00 am
  • added an answer This is the bind command you want: self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSED, self.close, self.nb)… May 11, 2026 at 9:00 am

Related Questions

I have image data and i want to get a sub image of that
There is a data file and some image files that I have to download
I have some scientific image data that's coming out of a detector device in
I have a XULRunner application that needs to copy image data to the clipboard.
I have the following code: Guid id = imageMetaData.ID; Data.LinqToSQL.Image dbImage = DBContext.Images.Where(x =>
I have written a CGI script that creates an image dynamically using GET data.
C# question (.net 3.5). I have a class, ImageData, that has a field ushort[,]
I have: image 1:Many imageToTag Many:1 tag I want to issue a query that
I have an image and on it are logos (it's a map), I want
I have an image of a basic game map. Think of it as just

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.