在opengl-es 2.0中渲染三角形的困难 [英] Difficulty in rendering triangles in opengl-es 2.0

查看:103
本文介绍了在opengl-es 2.0中渲染三角形的困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个opengl-es 2.0代码,用于使用文本文件中的数据渲染三角形,但我遇到的错误不是opengl的一般c或c ++错误,因此如果可以告诉我有关这件事的信息,对我来说太好了

This is an opengl-es 2.0 code which is used to render triangles using the data from text file but the errors I am getting is not of opengl its general c or c++ error so if you can tell me anything about that , it would be great for me

glGenBuffers(surftotal, uiVBO);
{
    for(surfnum=0; surfnum<surftotal; ++surfnum)
    {
            glBindBuffer(GL_ARRAY_BUFFER, uiVBO[surfnum]);
            size_t buf_size = 9*sizeof(GLfloat)*triNum[surfnum];
            GLfloat* const pData = malloc(buf_size);
            for(i=0; i<triNum[surfnum]; ++i) {
                memcpy(pData+i*9,   triArray[surfnum][i].pt1, 3*sizeof(GLfloat));
                memcpy(pData+i*9+3, triArray[surfnum][i].pt2, 3*sizeof(GLfloat));
                memcpy(pData+i*9+6, triArray[surfnum][i].pt3, 3*sizeof(GLfloat));
            }
            glBufferData(GL_ARRAY_BUFFER, buf_size, pData, GL_STATIC_DRAW);
            free(pData);
    }   
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glEnableVertexAttribArray(VERTEX_ARRAY);
    for(surfnum=0; surfnum<surftotal; ++surfnum)
    {
            glBindBuffer(GL_ARRAY_BUFFER, uiVBO[surfnum]);
            glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, 0);
            glDrawArrays(GL_TRIANGLES, 0, 3*triNum[surfnum]);
    }
    glBindBuffer(GL_ARRAY_BUFFER, 0);        //clean up, of course      

}   



但是这里说



But here it says

invalid conversion from ''void*'' to ''GLfloat*''



然后我将GLfloat再次更改为void它说:



Then I changed GLfloat to void again It says :

<pre lang="vb">src/Hello.cpp: In function ''int main(int, char**)'':
src/Hello.cpp:281: warning: pointer of type ''void *'' used in arithmetic
src/Hello.cpp:282: warning: pointer of type ''void *'' used in arithmetic
src/Hello.cpp:282: warning: pointer of type ''void *'' used in arithmetic
src/Hello.cpp:283: warning: pointer of type ''void *'' used in arithmetic
src/Hello.cpp:283: warning: pointer of type ''void *'' used in arithmetic




并且因为它的警告有一个.exe文件,所以当我尝试编译另一个
警告:




and because its warning there was a .exe file , when I try to compile it another
warning :

libEGL warning: use software fallback





after this a window pop up and goes nothing shown ... please elaborate me . I am not able to understand
also the other way to declare that glmapbufferOES don't work . If you want any other information or the whole code I can paste it.Waiting for reply



如果您还需要其他信息,请告诉我.
我有 http://bit.ly/ny5IMa 整个代码,你能告诉我问题出在哪里吗



if you want anyother information please tell me.
hi I have there http://bit.ly/ny5IMa whole of my code can you tell me where is the problem

推荐答案

如果您指出编译器在哪一行出现问题,将大大帮助 .

我一眼就怀疑这就是这个:
It would help substantially if you would indicate which line the compiler has a problem with.

I suspect from a quick glance that it''s this one:
GLfloat* const pData = malloc(buf_size);



在这种情况下,您可能需要记住将调用malloc的结果转换为类型.即



In which case, you may want to remember to type-cast the result of the call to malloc. I.e

GLfloat* const pData = (GLfloat*)malloc(buf_size);


我(简短地)看了看你的代码?
我会指出几件事:
1)首先,我只能看到3个错误检查实例.我还不确定您是否真的尝试发现问题所在.
我看不到对 glError [
I''ve looked (briefly) at your(?) code.

A couple of things I will point out:
1) Firstly, there''s only 3 instance that I can see of error checking. I''m not convinced yet that you''ve really tried to discover where the problem is.
I don''t see a single call to glError[^] anywhere!!

2) The data that the program depends on is not given nor explained. Depending on my mood I''ll try to fix a program, but rarely, if ever, am I prepared to try to determine what the necessary feed-data is. How do I know that''s not part of the screw-up error, after all?



Have you tried to trim the program back to the simplest program that will display a (fixed-pipeline) shaded quad?

Something else that''s just occurred to me - what''s the result of the attempt to compile and use the shader program? My laptop supports OpenGL 2.1, however it only supports GLSL version 1.2
Perhaps you''ve used code in your shader that is not supported by the GLSL implementation that you have? I''m certainly nobody to ask on things glsl related..

But depending on the setup of the environment and the polygons within it - you could see nothing as a direct consequence of the shaders not being compiled/linked correctly.

Looks like time you did some more investigating and less question-asking for a short-time. Don''t suppose that this is an example of copy/paste programming is it?


Lastly, what''s with the crazy-a


链接是什么?
您提供的链接指向代码项目的页面.因此,
http://bit.ly/ny5IMa [ http://www.codeproject.com/script/Answers/Entry.aspx?aid = 221622 [ ^ ]是吗?
link you gave above?
The link you provide points to a page at code project. So, what''s the go with http://bit.ly/ny5IMa[^]
and not the http://www.codeproject.com/script/Answers/Entry.aspx?aid=221622[^] that it is?


这篇关于在opengl-es 2.0中渲染三角形的困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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