void ScreenBuffer::drawPixel(int x, int y, double intensity) { int leftx = x * pixelWidth; int rightx = leftx + pixelWidth; int bottomy = y * pixelHeight; int topy = bottomy + pixelHeight; int p1 [] = {leftx , bottomy}; int p2 [] = {leftx , topy}; int p3 [] = {rightx , topy}; int p4 [] = {rightx , bottomy}; // cout << "dimensions of pixel square are: " // << p1[0] << ", " << p1[1] // << " -- " // << p3[0] << ", " << p3[1] << "\n"; glColor3d(intensity, intensity, intensity); glBegin (GL_POLYGON); glVertex2iv ( p1 ); glVertex2iv ( p4 ); glVertex2iv ( p3 ); glVertex2iv ( p2 ); glEnd(); checkGlErrors(); }
bool Program::attachShader(const Shader & shader) { if (!id) { id = glCreateProgram(); if (checkGlErrors()) return false; } glAttachShader(id, shader.getId()); if (checkGlErrors()) return false; return true; }
void flipScreenBuffer() { if( getConfig()->useOpenGL ){ checkGlErrors(); SDL_GL_SwapBuffers(); //glClear(GL_COLOR_BUFFER_BIT); } else { SDL_Flip(SDL_GetVideoSurface()); } }
GlObject::GlObject(NormalShader *s, int nVerts, GLfloat *vetPos, GLfloat *vetColor, int nNormals, GLfloat *vetNormals) { shader = s; numVerts = nVerts; numNormals = nNormals; modelMatrix = glm::mat4(1.f); glBindBuffer(GL_ARRAY_BUFFER, vboPos); glBufferData(GL_ARRAY_BUFFER, 3*numVerts*sizeof(GLfloat), vetPos, GL_STATIC_DRAW); checkGlErrors(); glBindBuffer(GL_ARRAY_BUFFER, vboColor); glBufferData(GL_ARRAY_BUFFER, 3*numVerts*sizeof(GLfloat), vetColor, GL_STATIC_DRAW); checkGlErrors(); glBindBuffer(GL_ARRAY_BUFFER, vboNormals); glBufferData(GL_ARRAY_BUFFER, 3*numNormals*sizeof(GLfloat), vetNormals, GL_STATIC_DRAW); checkGlErrors(); }
bool Program::link() { GLint Result = GL_FALSE; if (!id) { setErrMsg("No shaders to link"); return false; } glLinkProgram(id); if (checkGlErrors()) return false; glGetProgramiv(id, GL_LINK_STATUS, &Result); if (checkGlErrors()) return false; if (Result == GL_FALSE) { int length = 0; glGetProgramiv(id, GL_INFO_LOG_LENGTH, &length); if (checkGlErrors()) return false; errMsg.resize(length); glGetProgramInfoLog(id, length, NULL, &errMsg.front()); checkGlErrors(); errorFlagged = true; return false; } errorFlagged = false; return true; }
bool Program::use() { glUseProgram(id); return (!checkGlErrors()); }