在OpenGL中非常简单的纹理 [英] very simple texturing in OpenGL

查看:93
本文介绍了在OpenGL中非常简单的纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我希望在四边形上有一个简单的纹理。

我找不到一个简单的代码。

(我使用SDL与openGL一起工作)

解决方案

这些是我想到的东西



1.确定一个纹理格式说RGB888和图像大小,但功率为2

2.假设您知道如何设置基本的opengl事物(创建上下文,设置投影矩阵)

3.现在加载位图,并将像素值分配给指针。说'p''

4.现在用glEnable启用纹理(GL_TEXTURE2D)

5.然后你需要创建一个纹理并复制像素指针''p' '到那个纹理

6.创建纹理使用glGenTexture函数,这将返回该纹理的无符号整数id

7.使用glBindTexture函数将该纹理绑定到GL_TEXTURE2D

8.使用glTexImage2D将像素复制到纹理(或者你可以使用gluBuild2DMipmaps但它需要glu库,这个函数可以拍摄任何大小的图像。)

9.现在绘制一个使用glBegin(GL_QUAD)等语句的矩形并为每个顶点设置适当的纹理坐标。



到这个时候它会工作

也结帐 http://nehe.gamedev.net/tutorial/texture_mapping/12038/ [ ^ ]



希望这有帮助

jkchan

http://cgmath.blogspot.in/ [ ^ ]

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 )

解决方案

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/[^]


这篇关于在OpenGL中非常简单的纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆