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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:31:17+00:00 2026-05-25T22:31:17+00:00

I want to load this picture into a 2d texture and then draw it

  • 0

I want to load this picture into a 2d texture and then draw it onto the screen. The main problem is loading the picture into a texture variable. The follow code output the correct width and height and rgba but how do I put the data into a 3d texture.

#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
/* more includes... */
#include "stb_image.h"

using namespace std;

int main(int argc, char** argv) {
    int x,y,n;
    unsigned char *data = stbi_load("png.png", &x, &y, &n, 0);
    if (data == NULL) {
        // error
        cout << "Error, data was null";
    } else {
        // process
        cout << data << endl << endl;
    }
    stbi_image_free(data);

    cout << x << endl << y << endl << n;
    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-05-25T22:31:18+00:00Added an answer on May 25, 2026 at 10:31 pm

    First you need

    • a drawable (window, PBuffer, framebuffer)
    • a OpenGL context associated with the drawable

    You can use GLFW, SDL or GLUT for getting those (personally I recommend GLFW, if you need only one single window).

    Create a texture name with

    GLuint texture_name;

    void somefunction(…)
    {
    glGenTextures(1, &texture_name);
    glBindTexture(GL_TEXTURE_2D, texture_name);
    glPixelStorei(…); /* multiple calls to glPixelStorei describing the layout of the data to come */
    glTexImage2D(GL_TEXTURE_2D, miplevel, internal_format, width, height, border, format, type, data);
    }
    

    This was the quick and dirty explanation how to load it. Drawing is another business. I suggest you read some OpenGL tutorials. Google for “NeHe” or “Lighthouse3D”, or “Arcsynthesis OpenGL tutorial”.

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

Sidebar

Related Questions

I want to load this simple something into my Editor: Write:-repeat,write(hi),nl,fail. So that it
I want to open text files and load them into a RichTextBox. This has
I want to load the inside values from this xml code: <?xml version=1.0 encoding=UTF-8?>
I want to load some helper in a model. How to do this? Tried
I want to load a local file, example.pages in UIWebview. I tried with this
I would appreciate any help on this issue. Lets say I want to load
I'm having difficulty doing this seemingly simple task. I want to load XML files
Because I want to do things like load images from the web (see this
Here is the thing: I want to load a picture as a background filled
I have the following void: public void load() { //loading big picture from the

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.