Jump to content
  • Advertisement
Sign in to follow this  
Jossos

OpenGL 2 strange opengl problems - small window and reverse

This topic is 1420 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

2lk7fr4.jpg

 

Hello I'm having an issue where for some reason it only renders to a small center portion of the screen, as you see in the screenshot (I changed the glClearColor for both buffers so you can easilly see)

 

Render func:

void GAMELAUNCHER::Render()
{
	glBindFramebuffer(GL_FRAMEBUFFER, backend.frameBuffer);
	glClearColor(1.0f, 0.0f, 0.0f, 1.0f);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);

	backend.SetupPipelineForRender();

		gameState->Render(backend.pipeline);

	glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
	backend.FinishRender();
}

And Breaking those functions apart

void BACKENDSYSTEM::SetupPipelineForRender()
{
	pipeline.Perspective(fov, (float)screenWidth / (float)screenHeight, 0.1f, 10000.0f);

	pipeline.MatrixMode(VIEW_MATRIX);
	pipeline.LoadIdentity();
}

void BACKENDSYSTEM::FinishRender()
{
	glViewport(0, 0, screenWidth, screenHeight);

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glDisable(GL_DEPTH_TEST);
	glClear(GL_COLOR_BUFFER_BIT);

	pipeline.LoadIdentity();
	pipeline.Ortho(-1, 1, -1, 1, -1, 1);

	basicShader->Bind();
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, texture);
		glUniform1i(glGetUniformLocation(basicShader->GetProgramID(), "texture"), 0);

		pipeline.CalcMatrices(basicShader->GetProgramID());
		quad.Render();
	basicShader->Unbind();

	SDL_GL_SwapWindow(window);
}

Not sure why it's just a small window.

 

 

Also, everything is reversed in the scene for some reason. the translate's work correctly, -1 x goes left, +1 x goes right, However Positive rotation around the Y axis results in the model rotating anti-clockwise. the model you see should be holding the club in the other hand. Would this be a fault in any of the rendering code I've shown?

 

Thanks in advance.

 

-- ALSO ANOTHER PROBLEM

 

Whenever I do:

 

glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
No textures render at all.To get them working I have to do this in my shaders:
 
FragColor = vec4(texture2D(texture, TexCoord0).xyz, 1.0);

 

---- EDIT ---- Fixed the main problems I had posted, but this new one had taken me hours and I found no results on google.

 

I have 2 shaders

tileShader = new SHADER("Shaders/StandardShader.vs", "Shaders/TileShader.fs");
skinShader = new SHADER("Shaders/SkinningShader.vs", "Shaders/ShadingShader.fs");

and they each have 2 textures like so:

uniform sampler2D texture0;
uniform sampler2D texture1;

and then I do this:

glUniform1i(glGetUniformLocation(tileShader->GetProgramID(), "texture0"), 0);
glUniform1i(glGetUniformLocation(tileShader->GetProgramID(), "texture1"), 1);

glUniform1i(glGetUniformLocation(skinShader->GetProgramID(), "texture0"), 0);
glUniform1i(glGetUniformLocation(skinShader->GetProgramID(), "texture1"), 1);

In the shaders they do some stuff with the two textures mixing them together, however one of these shaders will only render ONE texture in place of both, depending on whichever I do the "new SHADER" on first(last works properly, first just has 1 texture, or is just sometimes completely black)

 

And I have no idea what the hell is causing this. I know my binding is fine, as swapping their "new SHADER" lines after each other makes them swap, one working and one not.

 

Any help is greatly appreciated.

Edited by Jossos

Share this post


Link to post
Share on other sites
Advertisement

What does this call look like "pipeline.Ortho(-1, 1, -1, 1, -1, 1);"?

What does "quad.Render();" look like? Im thinking its a problem with the quads vertices or texture coordinates assigned to them.

For the blending if you textures alpha channel is black (0) or doesnt have an alpha channel and defaults to black it might not show.

Share this post


Link to post
Share on other sites
 

What does this call look like "pipeline.Ortho(-1, 1, -1, 1, -1, 1);"?

What does "quad.Render();" look like? Im thinking its a problem with the quads vertices or texture coordinates assigned to them.

For the blending if you textures alpha channel is black (0) or doesnt have an alpha channel and defaults to black it might not show.

 

Oh man thanks, I had my quad be 0,0 to 1,1, but it should have been -1,-1 to 1,1. That problem is now fixed. By I still have the issue of the model being back to front and rotating the wrong way.

Share this post


Link to post
Share on other sites


Also, everything is reversed in the scene for some reason. the translate's work correctly, -1 x goes left, +1 x goes right, However Positive rotation around the Y axis results in the model rotating anti-clockwise. the model you see should be holding the club in the other hand. Would this be a fault in any of the rendering code I've shown?

Translation goes in 3 directions in general. What is with the other two's? Do they work as expected?

 

However, there is no real wrong or right, because it all is convention. You should pick a set of conventions and ensure that all works that way. For example, if you have a toolchain preparing your models, make sure that any export of the toolchain follows the conventions (so the runtime can expect all being well). Otherwise make sure that right after importing a model (placement, animations, ...) into the runtime, models (...) that do not follow the conventions are converted.

 

Typical things that need to be specified are at least:

  * left hand (LHS) or right hand (RHS) co-ordinate system

  * what are the right, up, and forward directions (considering the above spec.); e.g. right = +x, up = +y, forward = -z

  * direction of positive angled rotations; e.g. right handed

  * what is the standard front-facing direction of models; e.g. +z

  * what is the standard look-along direction of the camera; e.g. -z

  * what length does a world unit have (this plays a role for well-sized mode import); e.g. 1 world unit = 1 meter

 

For example: Having the (front clipping) camera as well as the model in initial orientation, when you see a model from the back but it has equipped its right hand as expected, then probably the front-facing of the model is wrong (rotated by 180 degree around up direction). If, on the other hand, you see a model from the back but it has equipped the left hand although the right hand was expected, then the model is probably imported as LHS (or RHS) but the application uses the other, resulting in a mirroring in one direction.

 

After defining the conventions, start to use simple models like a cube with differently colored sides. It is important that they are manually coded and not imported, so you know exactly that they follow your conventions. Then implement the transformations / math and ensure that they work as expected. After you have ensured that your system works like you want, you can start to import models from other sources. Because you rely on your system to do what you want, any anomalies now are probably based on the model itself.

Share this post


Link to post
Share on other sites

Fixed problem I had posted, but this new one had taken me hours and I found no results on google.

 

I have 2 shaders

tileShader = new SHADER("Shaders/StandardShader.vs", "Shaders/TileShader.fs");
skinShader = new SHADER("Shaders/SkinningShader.vs", "Shaders/ShadingShader.fs");

and they each have 2 textures like so:

uniform sampler2D texture0;
uniform sampler2D texture1;

and then I do this:

glUniform1i(glGetUniformLocation(tileShader->GetProgramID(), "texture0"), 0);
glUniform1i(glGetUniformLocation(tileShader->GetProgramID(), "texture1"), 1);

glUniform1i(glGetUniformLocation(skinShader->GetProgramID(), "texture0"), 0);
glUniform1i(glGetUniformLocation(skinShader->GetProgramID(), "texture1"), 1);

In the shaders they do some stuff with the two textures mixing them together, however one of these shaders will only render ONE texture in place of both, depending on whichever I do the "new SHADER" on first(last works properly, first just has 1 texture, or is just sometimes completely black)

 

And I have no idea what the hell is causing this. I know my binding is fine, as swapping their "new SHADER" lines after each other makes them swap, one working and one not.

 

Any help is greatly appreciated.

Edited by Jossos

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!