forgot to bind texture properly

This commit is contained in:
Ben Kyd
2020-01-17 00:50:29 +00:00
parent 083c93926f
commit 0d0b68540c
37 changed files with 7693 additions and 3110 deletions

View File

@@ -26,7 +26,7 @@ void FrameBuffer::SetPixel( int x, int y, glm::vec3 p )
uint8_t r = (uint8_t)( pow( p.r, gamma ) * 255.0f );
uint8_t g = (uint8_t)( pow( p.g, gamma ) * 255.0f );
uint8_t b = (uint8_t)( pow( p.b, gamma ) * 255.0f );
uint32_t col = 0xFF000000 | r << 16 | g << 8 | b;
uint32_t col = r << 24 | g << 16 | b << 8 | 0xFF;
Data[i] = col;
}

View File

@@ -21,14 +21,13 @@ struct Game
SDL_GLContext GlContext = nullptr;
};
void GLAPIENTRY
MessageCallback( GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar* message,
const void* userParam )
void GLAPIENTRY MessageCallback( GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar* message,
const void* userParam )
{
std::cout << "GL CALLBACK: type = " << type
<< ", severity = " << severity
@@ -74,8 +73,9 @@ int main()
// Time to actually load OpenGL
gladLoadGLLoader( SDL_GL_GetProcAddress );
glEnable( GL_DEBUG_OUTPUT );
glDebugMessageCallback( MessageCallback, 0 );
// Doesnt work
//glEnable( GL_DEBUG_OUTPUT );
//glDebugMessageCallback( MessageCallback, 0 );
Renderer renderer;
renderer.LoadShader();
@@ -86,6 +86,16 @@ int main()
framebuffer.SetPixel( 3, 1, { 1.0, 0.0, 0.0 } );
framebuffer.SetPixel( 4, 1, { 1.0, 0.0, 0.0 } );
framebuffer.SetPixel( 5, 1, { 1.0, 0.0, 0.0 } );
framebuffer.SetPixel( 1, 2, { 1.0, 0.0, 0.0 } );
framebuffer.SetPixel( 2, 2, { 1.0, 0.0, 0.0 } );
framebuffer.SetPixel( 3, 2, { 1.0, 0.0, 0.0 } );
framebuffer.SetPixel( 4, 2, { 1.0, 0.0, 0.0 } );
framebuffer.SetPixel( 5, 3, { 1.0, 0.0, 0.0 } );
framebuffer.SetPixel( 1, 3, { 1.0, 0.0, 0.0 } );
framebuffer.SetPixel( 2, 3, { 1.0, 0.0, 0.0 } );
framebuffer.SetPixel( 3, 3, { 1.0, 0.0, 0.0 } );
framebuffer.SetPixel( 4, 3, { 1.0, 0.0, 0.0 } );
framebuffer.SetPixel( 5, 3, { 1.0, 0.0, 0.0 } );
renderer.RegisterBuffer( &framebuffer, 0 );

View File

@@ -105,15 +105,16 @@ int8_t Renderer::RegisterBuffer( FrameBuffer* buffer, int layer )
// Load buffer as a texture into OpenGL
GLuint texture;
glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, buffer->GetWidth(), buffer->GetHeight(), 0, GL_RGB, GL_RGBA32UI, buffer->Data );
// Colour stored as uint32_t so 0xRRGGBBAA except no A
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, buffer->GetWidth(), buffer->GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer->Data );
FrameBufferRenderable fb =
{
buffer,
@@ -160,7 +161,7 @@ void Renderer::UpdateBuffer( int8_t id )
return;
FrameBuffer* buffer = mRenderQueue[id].Buffer;
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, buffer->GetWidth(), buffer->GetHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, buffer->Data );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, buffer->GetWidth(), buffer->GetHeight(), 0, GL_RGBA, GL_RGBA32UI, buffer->Data );
}
void Renderer::Render()
@@ -171,8 +172,8 @@ void Renderer::Render()
for ( size_t i = 0; i < mRenderQueue.size(); i++ )
{
FrameBufferRenderable* fb = &mRenderQueue[i];
glBindTexture( GL_TEXTURE_2D, fb->TextureID );
glBindVertexArray( fb->VAO );
glBindTexture( GL_TEXTURE_2D, fb->TextureID );
glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0 );
}
}

7666
src/thirdparty/stb_image.h vendored Normal file

File diff suppressed because it is too large Load Diff