Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ OpenGL
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 14-Dec-12 2:32am

1 solution

Rate this: bad
good
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 http://nehe.gamedev.net/tutorial/texture_mapping/12038/[^]
 
Hope this helps
jkchan
http://cgmath.blogspot.in/[^]
  Permalink  
v2
Comments
Amir Mahfoozi at 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)

  Print Answers RSS
0 OriginalGriff 389
1 Sergey Alexandrovich Kryukov 375
2 Maciej Los 295
3 King_Fisher 160
4 Garth J Lancaster 158
0 Sergey Alexandrovich Kryukov 11,069
1 OriginalGriff 5,743
2 Maciej Los 5,649
3 CPallini 3,879
4 BillWoodruff 3,584


Advertise | Privacy | Mobile
Web02 | 2.8.141030.1 | Last Updated 15 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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