在以下代码中我收到一个错误:
333 glGenBuffers(surftotal, uiVBO);
334 {
335 for(surfnum=0; surfnum<surftotal; ++surfnum)
336 {
337 glBindBuffer(GL_ARRAY_BUFFER, uiVBO[surfnum]);
338 size_t buf_size = 9*sizeof(GLfloat)*triNum[surfnum];
339 GLfloat* const pData = (GLfloat*)malloc(buf_size);
340 for(i=0; i<triNum[surfnum]; ++i)
341 printf("%d...",triNum[surfnum]);
342 {
343 memcpy(pData+i*9, triArray[surfnum][i].pt1, 3*sizeof(GLfloat));
344 memcpy(pData+i*9+3, triArray[surfnum][i].pt2, 3*sizeof(GLfloat));
345 memcpy(pData+i*9+6, triArray[surfnum][i].pt3, 3*sizeof(GLfloat));
346 }
347 glBufferData(GL_ARRAY_BUFFER, buf_size, pData, GL_STATIC_DRAW);
348 free(pData);
349 }
350 glBindBuffer(GL_ARRAY_BUFFER, 0);
351 glEnableVertexAttribArray(VERTEX_ARRAY);
352 for(surfnum=0; surfnum<surftotal; ++surfnum)
353 {
354 glBindBuffer(GL_ARRAY_BUFFER, uiVBO[surfnum]);
355 glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, 0);
356 glDrawArrays(GL_TRIANGLES, …Run Code Online (Sandbox Code Playgroud) 我发现我的片段着色器仅限于OpenGL ES视口的像素尺寸.
我可以创建一个"屏幕外片段着色器"或渲染环境,它具有更多像素用于渲染吗?
我正在调整问题,或者我想要理解OBJ文件中的顶点/索引/面.我想最终以编程方式解析OBJ文件,但首先我需要了解如何手动完成.我正在使用GLWallpaperService(由网络上的开发人员提供)中的示例进行调整来完成此操作.
我遇到的问题是它似乎与他提供的代码一起工作,以生成一个具有不同颜色面的通用立方体,他必须单独实现和绘制.我调整后的代码试图从我从搅拌机输出并插入值的坐标中绘制一个基本的立方体.
public class GLCube {
private final int _nrOfVertices = 8;
private FloatBuffer _vertexBuffer;
private FloatBuffer _normalBuffer;
private ShortBuffer _indiceBuffer;
public GLCube() {
this.init();
}
private void init() {
// 3 is the number of coordinates to each vertex.
_vertexBuffer = BufferFactory.createFloatBuffer(_nrOfVertices * 3);
_normalBuffer = BufferFactory.createFloatBuffer(18);
_indiceBuffer = BufferFactory.createShortBuffer(72);
// Coordinates for the vertexes of the cube.
float[] vertexCoords = {
/*
1f, 1f, 0f,
0f, 1f, 0f,
0f, 0f, 0f,
1f, 0f, 0f,
1f, 0f, -1f,
1f, …Run Code Online (Sandbox Code Playgroud) 如何从图形内存中读取纹理数据?一旦我创建了glTexture,如何回溯像素数据?
乐器鼓励我使用GL_SHORTs作为纹理坐标.我这样做是为了我只需要值0和1的四边形.
如果短路的精度足够,我还可以将GL_SHORT用于需要0到1之间的值的其他情况吗?如果是这样的话?
我是Xcode编程的新手,我正在尝试使用OpenGL创建一个iPhone游戏,支持60 FPS的视网膜显示,但运行速度太慢.我基于developer.apple上的GLSprite示例.我已经尽可能地优化了它,但它在模拟器上一直运行<30 FPS(我还没有在真实设备上测试它 - 也许它更快?).瓶颈似乎是绘制多边形 - 我使用了非常小的纹理(256x256 PNG)和像素格式(RGBA4444); 我已禁用混合; 我已将所有转换代码移至加载阶段,希望获得更好的性能; 一切都没有成功.我保持一个顶点数组存储一切为了这一步,然后绘制使用GL_TRIANGLES一个函数调用 - 因为我觉得它比调用多个调用glDrawArrays更快.当我达到大约120个顶点(每个矩形精灵6个)时,它开始滞后,但在许多地方我读过iPhone甚至可以处理数百万个顶点.下面的代码有什么问题?OpenGL是在iPhone上渲染图形的最快方式吗?如果没有,我还应该使用什么?
OpenGL加载代码,在开头只调用一次:
glViewport(0, 0, backingWidth, backingHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D,texture[0]); //Binds a texture loaded previously with the code given below
glVertexPointer(3, GL_FLOAT, 0, vertexes); //The array holding the vertexes
glEnableClientState(GL_VERTEX_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, uvCoord); //The array holding the uv coordinates
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
Run Code Online (Sandbox Code Playgroud)
纹理加载方法:
- (void)loadSprite:(NSString*)filename intoPos:(int)pos { //Loads a texture within the bundle, at the given position …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用在OpenGL ES 2.0中工作的立方体贴图进行反射贴图.我不确定我是否正确计算反射方向以传递到片段着色器中的samplerCube.
首先,我有Projection,Model和View矩阵以及一个组合的ModelView矩阵.这是我在GLSL中的顶点着色器的代码:
attribute vec4 Position;
attribute vec3 Normal;
uniform mat4 Projection;
uniform mat4 ModelView;
uniform mat3 Model;
uniform mat4 ModelViewProjectionMatrix;
uniform vec3 EyePosition;
varying vec3 ReflectDir;
void main()
{
gl_Position = Projection * ModelView * Position;
mediump vec3 EyeDir = normalize(Position.xyz - EyePosition);
// Reflect eye direction by normal, and transform to world space
ReflectDir = Model * reflect(EyeDir, Normal);
}
Run Code Online (Sandbox Code Playgroud)
我的假设是EyeDirection必须在对象空间中.(正确?)如何在对象空间中获取EyePosition?我是否只是通过逆ModelView矩阵变换摄像机位置(即总是在OpenGL中的{0,0,0}?)?
我试过这个但是我的片段着色器将所有颜色都着色,好像ReflectDir不正确.
有没有人有一个在Xcode中工作的OpenGL ES 2.0反射映射(带有samplerCube)的工作示例?
我从developer.Apple网站下载了示例代码GLPaint,使用OpenGL在Canvas上绘制图片.
我已经完成了GLPaint应用程序中的更改以满足我的要求.
现在我需要将绘图记录为m4v视频文件,该文件应该集成我在绘制图像时说出的口头指令.
例如:
点击"绘制和录制"按钮后,我开始画一个圆圈并说出"这是一个圆圈".
单击完成按钮后,结果应为包含绘图操作的视频文件,其中包含"这是一个圆圈"的声音
我研究了这个主题,但我没有找到任何好的方法来完成这个功能.
PaintingView.h EAGLContext*context;
// OpenGL names for the renderbuffer and framebuffers used to render to this view
GLuint viewRenderbuffer, viewFramebuffer;
// OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist)
GLuint depthRenderbuffer;
GLuint brushTexture;
CGPoint location;
CGPoint previousLocation;
Run Code Online (Sandbox Code Playgroud)
PaintingView.m
// Handles the start of a touch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self bounds];
UITouch* touch = [[event touchesForView:self] …Run Code Online (Sandbox Code Playgroud) 我正在尝试绘制这里引用的程序范围.
我修改了一下,以便我可以使用OpenGL ES 2.0的glDrawElements方法
这是我的createSphere版本:
GLfloat sphereVerticies[10000]={0.0};
GLubyte triangleIndices[15000]={0};
int createSphere (GLfloat spherePoints[], GLubyte triangleIndices[], GLfloat fRadius, GLfloat step)
{
int points = 0;
GLfloat uStep = DEGREES_TO_RADIANS (step);
GLfloat vStep = uStep;
unsigned long index=0;
for (GLfloat u = 0.0f; u <= (2 * M_PI); u += uStep)
{
for (GLfloat v = -M_PI_2; v <= M_PI_2; v += vStep)
{
triangleIndices[index++]=points;
triangleIndices[index++]=points+1;
triangleIndices[index++]=points+2;
triangleIndices[index++]=points+2;
triangleIndices[index++]=points+3;
triangleIndices[index++]=points;
points++;
spherePoints[(points - 1) * 3] = fRadius * cosf(v) …Run Code Online (Sandbox Code Playgroud) 我知道openGL用于游戏,但是可以在Android Views等东西上使用OpenGL吗?例如,单击按钮将导致按钮(使用OpenGL爆炸/跳舞/ etc/etc).