Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 19 Dec 2012
Offline Last Active Apr 29 2015 02:41 AM

Topics I've Started

2 strange opengl problems - small window and reverse

22 November 2014 - 11:02 PM



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);




	glClearColor(0.0f, 0.0f, 1.0f, 1.0f);

And Breaking those functions apart

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


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

	glBindFramebuffer(GL_FRAMEBUFFER, 0);

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

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



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.




Whenever I do:



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.

glViewport Makes no sense

20 September 2014 - 09:37 AM



Ok So the two viewports refuse to go fullscreen, for reasons I cannot comprehend.



void GAME::DrawToFBO(bool half, float CameraOffset)
	glBindFramebuffer(GL_FRAMEBUFFER, FBO);	// Modify only 'FBO' screen



	// Init View

	if (half)
		m_pipeline.Perspective(fov, ((float)g_graphicsManager->GetWidth()) / (float)g_graphicsManager->GetHeight(), 0.01f, 1000.0f);
		m_pipeline.Perspective(fov, (float)g_graphicsManager->GetWidth() / (float)g_graphicsManager->GetHeight(), 0.01f, 1000.0f);
	m_pipeline.Translate(-m_camera->GetPos().x, -m_camera->GetPos().y, -m_camera->GetPos().z);

	// Right
	glViewport(0, 0, g_graphicsManager->GetWidth() / 2, g_graphicsManager->GetHeight());
	m_pipeline.Translate(-CameraOffset, 0.0f, 0.0f);

	// Left
	glViewport(g_graphicsManager->GetWidth() / 2, 0, g_graphicsManager->GetWidth() / 2, g_graphicsManager->GetHeight());
	m_pipeline.Translate(CameraOffset, 0.0f, 0.0f);

I'm not even sure how glViewport works, and google refuses to give anything useful. I thought specifying the pixels would work, but apparently not? And I've fiddled with the values for ages. It makes absolutely no sense. It seems calling glViewport twice seems to scale them both down for some reason.


Any help is appreciated.




By the way I'm trying to make a little thing for the oculus rift. If anyone has useful resources, feel free to share, although I'm obviously not that far just yet, until I can fix this stupidity.



Opengl Spazzing out for no reason

17 September 2014 - 07:16 AM

So I'm making a c++ and opengl app, with bone transformations, and it is spazzing out for no reason. And I really mean no reason. I spent weeks on this app without any problems. Character walked etc, looked nice. Today I added shadows to the shader, no problem. Later on it started going crazy. like the matrices were totally distorted and the screen is raped with random triangles going crazy. Seizure inspiring.


Luckilly I had backed up this program about 8 times. Every single other previous version is doing the exact same thing. No other project is acting this way.


What the hell is going on? I can't find any problem in the code. This happened right after nvidia update, so not sure how to go about fixing this...


EDIT: If i Freeze the animation (as in only render same animtime constantly), it still spazzes out. What the hell is going on?? Doesn't happen when I negate the bone transformations from the shader though.

Multitexturing not working

01 July 2014 - 11:03 AM

Ok, so I'm trying to get this shader to load 4 textures and blend them together (for tiling reasons).

#version 330

in vec2 TexCoord0;

uniform sampler2D gTex0;
uniform sampler2D gTex1;
uniform sampler2D gTex2;
uniform sampler2D gTex3;

out vec4 FragColor;

void main()
    vec4 color1 = texture2D(gTex0, TexCoord0);
    vec4 color2 = texture2D(gTex1, TexCoord0);
    vec4 color3 = texture2D(gTex2, TexCoord0);
    vec4 color4 = texture2D(gTex3, TexCoord0);

    color1 = color1 * (1 - TexCoord0.x) * TexCoord0.y;
    color2 = color2 * (1 - TexCoord0.x) * (1 - TexCoord0.y);
    color3 = color3 * TexCoord0.x * (1 - TexCoord0.y);
    color4 = color4 * TexCoord0.x * TexCoord0.y;

    FragColor = color1 + color2 + color3 + color4;

If i do 'FragColor = color1' (or any of the colors, like FragColor = color3 etc) it draws the texture, fading from its full color to black as it should do. Each of these textures work on their own, but when trying to use 2 or more (such as "FragColor = color1 + color2;"), it just renders black for some reason.

I can switch the color1/color2/color3/color4 in the shader without touching any other code and it renders that texture, so  im guessing that it is loading in all of the textures correctly.


If you need to see more code let me know, but it feels like the error is within the fragment shader itself.



A couple of small problems

28 January 2014 - 04:37 AM



I'm having a few issues with my application, and have a few queries. If you can help with any of them it would be greatly appreciated (These were all problems I gathered from not being able to find a solution on google).


I will list them here tl;dr version - maybe you can see what you might know:


1. Mipmapping isn't working

2. blending textures/quads to make a smooth transition between separate textures - not sure how to approach this

3. Being able layer 2 textures, or one texture with transparent parts showing a unique color (need multiple possible colors for a single object)

4. Importing Maya/3dsMax animation - More looking for guidance - will not attempt this in the next few months, but maybe after.



(Not OpenGL related, but I don't want to make too many topics - let me know if I should put these in a seperate thread)


5. How to determine if a chunk is in camera view - i.e. what to not render.

6. RTS drag selection - I know how to do one selection (with unit represented as a sphere and raysphering with the mouse), but how to drag a box like in all rts games, and have all units within that selected? I'm sure the math is really simple but I can't think of it.




Ok here are the questions in full:




1. Firstly, when I load a texture with mipmapping it just gives me a plain white texture (with value of -1). If I don't use mipmapping (enter mipmap as false), the texture renders fine, but looks like crap a long distance away.


My code is here:

int GRAPHICS::LoadTexture(const char *filename, bool mipmap, bool repeat)
	unsigned int id;
	glGenTextures(1, &id);
	SDL_Surface* img = IMG_Load(filename);

	if (img == NULL) 
		OutputDebugString("\" failed to load.\n");
		return -1;

	SDL_PixelFormat form = {NULL, 32, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff, 0, 255};
	SDL_Surface *img2 = SDL_ConvertSurface(img, &form, SDL_SWSURFACE);

	if (img2 == NULL)
		OutputDebugString("\" failed to load. img2 == -1\n");
		return -1;

	glBindTexture(GL_TEXTURE_2D, id);


	// Mipmapping
	if (mipmap)
		gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, img2->w, img2->h, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, img2->pixels);

	// Min Filter
	if (mipmap)

	// Repeat
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat ? GL_REPEAT : GL_CLAMP );
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat ? GL_REPEAT : GL_CLAMP );


	return id;

Here's my Init function if you want to know that:

void GRAPHICS::Init(int width, int height, bool fullscreen)
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	Refresh(width, height, 45.0f, fullscreen);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations


And the refresh function:

void GRAPHICS::Refresh(int width, int height, float fov, bool fullscreen)
	if (fullscreen)
		SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE | SDL_OPENGL | SDL_FULLSCREEN);
		SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE | SDL_OPENGL);
	glViewport(0, 0, width, height);
		gluPerspective(fov, ((float)width*2) / (float)height, 0.1, 500.0);

2. Secondly, I need to have my textures blend together. I can't really describe it with words so I will post an image:




Left is my game so far, you can see the tiles don't blend, on the right is empire earth, the kind of thing I'm wanting to do. It's early enough that I can restructure my tile system. but I am not wanting to make a unique texture for blending every combination of tiles (coz there's a tonne if I want many variants of the tiles)




3. Thirdly, I want part of a texture to change color. I'm wanting to make an RTS - meaning many players can use the same units, but each unit needs to have part of their texture be a different colour. I do not know how to do this. I want to only need to load each object once. Look at right image above, see the blue on the little man, you can make this color anything in that game. That is what I am wanting.


What I was thinking with this is that If I could somehow just apply first a color (like blue or red), and on top of that apply the normal texture, and that texture's transparent parts will show through the color underneath. (For example, I could do glColor3f(1.0f, 0.0f, 0.0f) then glCallList of the object)




4. Fourthly, this is not so urgent, as I don't think I will implement this anytime soon, but is there a way to export animation the same way I export obj files? obj files are so good because they display each vertex, and I just read this data in. That's how I got the trees and the white dude in my scene, but I can't bring in any animation unless I export each frame as an object - something I'm not wanting to do.


I use Maya/3dsMax, any guidance is appreciated.




5. In my game, I have the world made of chunks, and each chunk contains 4x4 reference to tiles(I think it's better than just tiles on their own, maybe not feel free to give your opinion - I'm sure they might be helpful) - Is there a way to determine if one of these areas is not in view? At the moment I just draw everything, even if I can only see a few tiles.





6. RTS drag selection - Most info given in tl;dr -  I already have a way to get opengl positions from the mouse (close and far to cast ray in right direction), I'm just not sure of how to draw a box (which would be 2D for the player) and have it know everything inside. I mean, the camera can rotate, then might start dragging from a spot, and drag across many screens, making the start point actually off screen. So many problems, not sure how to solve.




Any help/or suggestions with any of these things will be greatly appreciated. I will tend to this thread when I'm not working. I am not a good programmer, so some of these might be really obvious, and I'm sorry if that is so.