bind a bitmap raw data as texture to gl

Started by
4 comments, last by satanir 10 years, 5 months ago

hi,
I am receiving a bitmap of size 800 by 600 with RGB 24 bits. When I receive this bitmap from the other machine, I need to bind it to gl widget.
what crossed my mind is to do the following, however I am not quite sure if it is correct:

    initializeGLFunctions();

    GLuint vboId;

    glBindBuffer(GL_ARRAY_BUFFER, vboId);

    glBufferSubData(GL_ARRAY_BUFFER, 0, 800 * 600 * 3 * sizeof(int), &buffer[0]);

    glBindBuffer(GL_ARRAY_BUFFER, 0);

is this the right way to bind bitmap to gl?
I would also thank if you mention how to declare the vboId in the second line.
Advertisement

is this the right way to bind bitmap to gl?

Nope. You're creating a vertex buffer with that but want to create a texture. Try out "tutorial opengl texture mapping" in your favorite search engine.

The terms of interest are: glGenTexture, glBindTexture, glTexParameter, glTexImage2D, and companions. However, You need some geometry (a rectangle would be sufficient in your case) to map the texture onto the screen, for which purpose a vertex buffer can (better: should, nowadays) be used.

There you go - http://ogldev.atspace.co.uk/www/tutorial16/tutorial16.html

I just started with OpenGL...

but I wrote this as a demonstration of uploading a image to a texture.

http://bitpatch.com/downloads/glTex_example.cpp

this shows how to bind an image to texture and not a bitmap.

There you go - http://ogldev.atspace.co.uk/www/tutorial16/tutorial16.html

this shows how to bind an image to texture and not a bitmap.
The same, except he loads an image from disk and you already have it in memory.

This topic is closed to new replies.

Advertisement