Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 )
Posted

1 solution

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 http://nehe.gamedev.net/tutorial/texture_mapping/12038/[^]

Hope this helps
jkchan
http://cgmath.blogspot.in/[^]
 
Share this answer
 
v2
Comments
Amir Mahfoozi 15-Dec-12 7:57am    
+5

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900