Click here to Skip to main content
14,333,317 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi I want has a simple texturing on a quad .
I can't find a simple code for that.
( I use SDL for work with openGL )

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

These are the thing coming to my mind

1. Decide a texture format say RGB888 and image size but be a power of 2
2. assuming you know how to setup basic opengl things(creating context,seting up projection matrix)
3. Now load the bitmap , and assign the pixel values to a pointer. say 'p'
4. now enable texturing with glEnable(GL_TEXTURE2D)
5. Then you need to create a texture and copy the pixels pointer 'p' to that texture
6. Create texture use glGenTexture function, this will returns an unsigned integer id for that texture
7. Bind that texture to GL_TEXTURE2D using glBindTexture function
8. copy your pixels to texture using glTexImage2D (or you can use gluBuild2DMipmaps but it needs glu library,this function can take image of any size.)
9. Now draw a rectangle using glBegin(GL_QUAD) etc statements and set appropriate texture coordinates for each vertex.

By this time it will work
also checkout the tutorial at[^]

Hope this helps
Amir Mahfoozi 15-Dec-12 7:57am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100