Tag: opengl es

麻烦简单的VBO示例

我试图让一个超级简单的GLFW和VBO示例运行,但我被卡住了。 我已经将glBegin和glEnd用于其他项目,但我正在尝试更新我的代码以使用OpenGL ES 2,但是现在我只想尽可能向前兼容。 从网上的一些例子中,我提出了以下代码: #include #include #include #define bool int #define true 1 #define false 0 const int width = 800; const int height = 600; bool opened = true; GLuint glTriangle; GLfloat triangle[] = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, }; void init() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glGenBuffers(1, […]

如何将2D显示坐标映射到3D OpenGL空间

我正在开发一款移植到Android上的3D游戏,我希望在3D游戏过程中使用触摸事件。 我需要3D空间中的点,就在靠近剪裁平面上,但我能得到的只是来自Android显示器的2D坐标。 那么,有没有办法将这些(x,y)坐标映射到3D空间中的(x,y,z)坐标? 编辑 好吧,我正在制作一个赛车游戏,我想在课程中插入一些项目,具体取决于我点击的位置。 我有这个function: void racing_mouse_cb(int button, int state, int x, int y) { //parameters (x,y) are coords of a display set_ill_fish(get_player_data( local_player())->view); } 但是现在我在一个距离的玩家面前插入物品: void set_ill_fish(view_t view) { item_locs[num_items].ray.pt.x = view.plyr_pos.x; item_locs[num_items].ray.pt.z = view.plyr_pos.z – 5; item_locs[num_items].ray.pt.y = find_y_coord(view.plyr_pos.x, view.plyr_pos.z – 5) + 0.2; item_locs[num_items].ray.vec = make_vector(0, 1, 0); . . . […]

为什么FreeImage以BGR格式加载图像?

我使用Android NDK和FreeImage库编写游戏,将图像加载到我的游戏中。 它以BGR格式加载图像。 可以加载RGB格式吗? 或者我需要手动交换R和B组件? 编辑 我的设备是三星Galaxy S4(armv7 archtecture)。 这是代码` FIMEMORY* fiStream = FreeImage_OpenMemory((BYTE*)data, size); FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(fiStream); if (FreeImage_FIFSupportsReading(fif)) { dib = FreeImage_LoadFromMemory(fif, fiStream, 0); } if (!dib) return; data_ = FreeImage_GetBits(dib); width_ = FreeImage_GetWidth(dib); height_ = FreeImage_GetHeight(dib); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width_, height_, 0, GL_RGB, GL_UNSIGNED_BYTE, data_ );

如何将AVFrame转换为glTexImage2D使用的纹理?

如你所知AVFrame有2个属性:pFrame-> data,pFrame-> linesize。 我从video/sdcard/test.mp4(android平台)读取帧后,转换为RGB AVFrame副: img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, target_width, target_height, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL); if(img_convert_ctx == NULL) { LOGE(“could not initialize conversion context\n”); return; } sws_scale(img_convert_ctx, (const uint8_t* const*)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize); 我转换后得到了pFrameRGB。 我需要使用glTextImage2D在opengl中对其进行纹理处理: // Create The Texture glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, data); //我不知道这里的数据是pFrameRGB->数据与否,如果没有,如何将其转换为glTextImage的适当格式,这样我就可以使用AVFrame和gltextImage2D在opengl中显示video。 非常感谢你的所有帮助。

OpenGL ES片段着色器可以更改片段的深度值吗?

OpenGL ES 2.0中的片段着色器可以改变像素的Z值(深度)吗? 如何在OpenGL ES 2.0中实现这一目标?

iPhone – 使用C ++教程/片段的OpenGL

关于如何在iPhone上通过C / C ++使用OpenGL,是否有任何好的教程或代码片段?

glColor4f() – alpha值的效果

我正在使用glColor4f()。 令人惊讶的是,更改alpha,即第四个参数不会导致透明度发生任何变化。 代码段是: const GLfloat squareVertices[] = { 0.5, 0.5, 0.0, -0.5, 0.5, 0.0, 0.5, -0.5, 0.0, -0.5, -0.5, 0.0}; glEnableClientState (GL_VERTEX_ARRAY); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColor4f (1.0, 0.0, 0.0, 0.5); glLoadIdentity (); glTranslatef(0, 0, -5); glVertexPointer(3, GL_FLOAT, 0, squareVertices); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 任何指向我可能出错的地方?

使用OpenGL ES 1.1中的顶点缓冲对象和ES 2.0进行绘制

我是openGL的新手。 我使用苹果文档作为我的主要参考资料http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html#//apple_ref/doc/uid/TP40008793-CH107-SW6 我的问题是我使用的是openGL ES 1.1而不是2,因此清单9-3中使用的函数如glVertexAttribPointer , glEnableVertexAttribArray都无法识别…… 🙂 我试图进行本文档中描述的优化:将索引和顶点保存为包含其所有数据的结构:位置,颜色(清单9-1) typedef struct _vertexStruct { GLfloat position[3]; GLubyte color[4]; } VertexStruct; const VertexStruct vertices[] = {…}; const GLushort indices[] = {…}; 并使用清单9-2,9-3中的VBO 正如我所提到的,openGL ES 1.1中不存在一些在那里使用的函数。 我想知道是否有一种方法可以在ES 1.1中使用其他代码吗? 谢谢,亚历克斯 根据基督徒的回答编辑,尝试使用glVertexPointer,glColorPointer。 这是代码,它打印多维数据集,但没有颜色…… :(。任何人,是否可以使用ES 1.1这样的方式使用VBO typedef struct { GLubyte red; GLubyte green; GLubyte blue; GLubyte alpha; } Color3D; typedef struct […]

什么时候OpenGL完成函数指针?

OpenGL有许多直接指针的函数 。 其中一些从这些指针中读取数据 ,另一些则将数据 写入这些指针 。 但是,OpenGL函数通常不会立即执行。 通常,当您绘制某些内容时,绘图需要一段时间才能完成。 那么我怎么知道OpenGL何时完成了我给它的指针呢?