Reputation: 57
this is my code so far(i write it from book(OpenGl Es 2.0 Programming Guide)): i used precompiled Header name "pch.h"
#include"Pch.h"
typedef struct
{
GLuint programData;
}UserData;
void Render(ESContext* escontex);
int init(ESContext *escontex);
int main()
{
ESContext escontext;
UserData userData;
esInitContext(&escontext);
escontext.userData = &userData;
esCreateWindow(&escontext, L"Hello World!", 800, 600, ES_WINDOW_RGB);
esRegisterDrawFunc(&escontext, Render);
esMainLoop(&escontext);
}
int init(ESContext*escontex)
{
UserData *userData;
const char vShaderStr[] =
"attribute vec4 vPosition; \n"
"void main() \n"
"{ \n"
" gl_Position = vPosition; \n"
"} \n";
const char fShaderStr[] =
"precision meniump float; \n"
"void main() \n"
"{ \n"
"gl_FragColor(1.0,0.0.1.0.1.0); \n"
"}; \n";
GLuint programObject;
GLuint vertexShader;
GLuint fragmentShader;
vertexShader = LoadShader(GL_VERTEX_SHADER, vShaderStr);
fragmentShader = LoadShader(GL_FRAGMENT_SHADER, fShaderStr);
programObject = glCreateProgram();
if (programObject == 0) return 0;
glAttachShader(programObject, vertexShader);
glAttachShader(programObject, fragmentShader);
glBindAttribLocation(programObject, 0, "vPosition");
glLinkProgram(programObject);
userData->programData = programObject;
glUseProgram(userData->programData);
}
GLuint LoadShader(GLenum type, const char* shaderSrc)
{
GLuint shader;
GLint compile;
shader = glCreateShader(type);
if (shader == 0) return 0;
glShaderSource(shader,1 , &shaderSrc, NULL);
glCompileShader(shader);
glGetShaderiv(shader, GL_COMPILE_STATUS,&compile);
return shader;
}
void Render(ESContext* escontex)
{
glViewport(0, 0, escontex->width, escontex->height);
glClear(GL_COLOR_BUFFER_BIT);
GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f };
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
eglSwapBuffers(escontex->eglDisplay, escontex->eglSurface);
}
my problem is when i compile this i get error:"LoadShader Identifier not Found!" what is the problem?
and for the second question is there anything wrong with this code?
Upvotes: 0
Views: 781
Reputation: 2985
You are calling LoadShader()
before it is defined. To fix the issue put a function declaration at the top of your file.
#include"Pch.h"
typedef struct
{
GLuint programData;
}UserData;
void Render(ESContext* escontex);
int init(ESContext *escontex);
// this line here is new
GLuint LoadShader(GLenum type, const char* shaderSrc);
int main()
{
ESContext escontext;
...
Upvotes: 2