Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
brian
Sep 11, 2001
I obtained this title through beard tax.

So I was trying to make a breakout clone in a day and I got most of it done, but i'm having this bizarre problem where unless it's running in the VS debugger, it doesn't create half the stuff that it should (like boxes for the ball to hit and the paddle) and I have no idea how to fix it, it's got quite a bit of quick hardcoding stuff I don't usually do so I don't really know what's causing it at all.

Here's it in the debugger:



And out of it:



Here's the project file and whatnot, ignore the name of the project it was just an old project already set up for OGL/SDL.

Thanks in advance if anyone can help or has any idea what's causing it :(

Adbot
ADBOT LOVES YOU

brian
Sep 11, 2001
I obtained this title through beard tax.

Luminous posted:

I would agree.

Looking through the code, you have no initialization for m_bIsEnabled for BreakoutBox. You also never call your Enable function. But you do check IsEnabled in BreakoutApp in your Update function.

That'd be where I would start with.

Ha I spent two days after reading ultra inquisitor's post looking for something uninitialised and completely missed it, that's sorted it, thanks fellas.

brian
Sep 11, 2001
I obtained this title through beard tax.

Ok another question for you dapper fellas, how do I copy a texture from one handle to another in openGL without copying the pixels manually? I want to create a faux-motion blur effect by taking the previous frame and doing a simple fragment shader blend with the current one, I can get the current framebuffer using the framebuffer EXT and it's stored in an image handle but that handle is linked to the FBO so whenever the FBO is drawn to it's overwritten. I know I can detach the current image and attach a different one but that doesn't seem like a particularly good way to go about it but I could be wrong, would using an alternating color attachment each frame do the job? Any help would be fabbo.

brian
Sep 11, 2001
I obtained this title through beard tax.

Well I got that working like that, but now i'm having a buttload of trouble getting GLSL to work properly to blend it, the GLSL code is fine (tested in shader designer) but applying it correctly is hurting my head, at the moment I get it displaying without any noticable blur, with the alpha channel not working and there being a load of flickering, is there a way to blend the textures without using shaders because the whole glTexEnv stuff is hurting my already broken brain :(

brian
Sep 11, 2001
I obtained this title through beard tax.

Here's the main gl stuff, the ShooterWorld::draw() function just draws a series of sprites from the world, here's the sprite drawing code, I tried it with your fragment jobby but it just produces a pure black window because I assume i'm doing something wrong (I set the motionVec to (5,0) since that's the speed the camera and ship move but that's probably wrong too. I don't quite understand why it needs a direction if everything is moving anyway since the next frame will be further along the sprite than the second one thus causing the same effect right?

Any help would be fabbo fella!

brian
Sep 11, 2001
I obtained this title through beard tax.

Well it works (not correctly and really oddly) if I do a simple gl_FragColor = texColor1 + texColor2 type thing but then again I have no idea what i'm doing wrong, i've rejigged it so many times just trying to get it to work that i've lost any clue on what i'm doing and the whole file is a mess, it was just to quickly test it before I clean it up but it's turned awry! There's an issue where if I have the FBO go to one color attachment the other one gets turned to pure black despite nothing being done to it, which could be the cause but that wouldn't explain why it works the aforementioned simple way. I'm so horribly confused I don't usually do alot of graphics programming beyond simplistic sprites and particles so my understanding of the GL state system is spotty and I just tend to try things until it works instead of thinking about it correctly, that said I can't seem to wrap my head around the processes involved with FBOs and shaders when it comes to textures because of the whole removing the fixed function pipeline jobby.

brian
Sep 11, 2001
I obtained this title through beard tax.

Actually the FBO on its' own works fine, if the shaders aren't enabled I can get a mini viewport of the same scene as the main viewport and it works great, when I do two color attachments and alternate frames on which they're assigned by glDrawBuffer(), at any one frame one will have the correct frame while the other will be blank (pure black), as if by not assigning it means the texture info gets deleted.

Anyhoo here's my crappy shader code:

test.vert:
code:
void main(void)
{
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_TexCoord[1] = gl_MultiTexCoord1;
	
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
test.frag
code:
uniform sampler2D TextureUnit0;
uniform sampler2D TextureUnit1;

void main()
{
	vec4 value1 = texture2D(TextureUnit0, vec2(gl_TexCoord[0]));
	vec4 value2 = texture2D(TextureUnit1, vec2(gl_TexCoord[1]));
	
	vec4 color = (value1 + value2);

	gl_FragColor = color;
}
Note that the TexCoords should be defined the same:

code:
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 0);
glVertex2i(0, 0);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 1);
glVertex2i(0, 512);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 1);
glVertex2i(1024, 512);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 0);
glVertex2i(1024, 0);
Yet when I use the gl_TexCoord[0] for both it produces a slightly better result (that's still horribly wrong). I can include the whole project if you want to see what I mean it's rather bizarre and alpha doesn't work at all it just has white where any alpha is.

As for the fixed function pipeline I was under the impression by using any vertex or fragment shader it goes around the usual processes that gl performs (like having to transform vertices with ftransform() or modelview * vertex).

Anyhoo I wasn't really expecting the motion blur to work as much as it just to be the correct image blended with a black image but it doesn't work correctly at all.

edit: Pictures:

Shader on, both using gl_MultiTexCoord0



Shader on, using gl_MultiTexCoord0 and gl_MultiTexCoord1



Shader off, showing FBO working fine

brian fucked around with this message at 00:16 on Oct 11, 2008

brian
Sep 11, 2001
I obtained this title through beard tax.

Well the quad positioning is fine, it's still using the gluOrtho2D I set up earlier, I mean if it wasn't positioned right it wouldn't show at all, I mean the FBO texture on its' own displays fine but for some reason the shader stuff messes up the alpha and whatnot as seen in the pictures above. If it's not too much trouble can one of you fellas look through the source, i'm using pretty much copy and pasted shader set up stuff from examples. Note that the same behaviour happens without the glTexEnv functions being called unless you change the mode from GL_BLEND in which case it goes back to just being a blank screen.

http://pastebin.com/f70e2d9a9

edit: i'll totally give the Accumulation stuff a try thanks!

brian fucked around with this message at 01:58 on Oct 11, 2008

brian
Sep 11, 2001
I obtained this title through beard tax.

Is there something I need to set to turn the accumulation buffer on? Even when doing the tutorial with its' sample project and doing the exact thing it says I get absolutely no visible change, yet it works on another example using GLUT. I've just spent the last 2 hours searching through GLUT's source code which is about the most circularly frustrating thing ever, is it graphics card dependent or something?

Also in other news the whole one being blank when the other one was drawn to was entirely down to me being an idiot and putting the clear color buffer bit in the wrong place, so if I can get this whole accumulation razmatazz working it should be fine.

Ideally i'd like to do it with shaders if accumulation buffers are going to be an issue but for now i'd just like to get it working.

edit: Apparently it's to do with windows window creation so i'm looking into that.

edit2: Got the accumulation buffer working! Now I just need to get the blur working correctly, thanks fellas for all your help!

edit3: Totally works great, the only problem is that the main ship doesn't really move around the screen much so it looks oddly clear when everything else being blurred, maybe I can fake it somehow with a different texture or something.

brian fucked around with this message at 23:17 on Oct 11, 2008

brian
Sep 11, 2001
I obtained this title through beard tax.

How do I make a smaller texture out of an existing loaded texture in openGL? I want to be able to turn a frame in a sprite sheet into a whole texture so I can repeat it over an area, I know it's fairly simple if it's just a single texture so i've been trying to work out how to seperate a section of an existing texture into a new texture handle. I've looked at glCopyTexSubImage2D but it seems to act on the read buffer, is there any way I can do this other than seperating the sprites in the spritesheet into seperate textures at load time?

brian
Sep 11, 2001
I obtained this title through beard tax.

I'm having trouble doing mouse picking using the opengl selection buffer, for some reason whatever i'm doing wrong is resulting in it returning every object on screen and not in the area around the mouse cursor, I think i'm doing the gluPickMatrix call right so i'm a bit confused. Here's the relevant code:

code:
void GPHMain::GLSelectionRender(int x, int y)
{
	GLuint selectionBuffer[64];
	GLint viewport[4];

	glSelectBuffer(64,selectionBuffer);
	glRenderMode(GL_SELECT);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

	glGetIntegerv(GL_VIEWPORT,viewport);
	gluPickMatrix(x,viewport[3]-y, 2,2,viewport);
	glLoadIdentity();
	gluPerspective(60, 1.0, 0.0001, 1000.0);

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
	m_pCamera->ViewScene();

	glInitNames();	

	for(int i = 0; i < m_vObjects.size(); i++)
	{
		glPushName(m_vObjects[i]->GetName().getHash());
		m_vObjects[i]->Render();
		glPopName();
	}

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	glMatrixMode(GL_MODELVIEW);

	glFlush();

	int numHits = glRenderMode(GL_RENDER);

	GLuint names, *ptr, minZ,*ptrNames, numberOfNames;

	ptr = (GLuint *)selectionBuffer;
	minZ = 0xffffffff;
	for (int i = 0; i < numHits; i++) {	
		names = *ptr;
		ptr++;
		if (*ptr < minZ) {
			numberOfNames = names;
			minZ = *ptr;
			ptrNames = ptr+2;
		}

		IPhysicsObject* pObj = GetPhysObject(*(ptr+2));

		ptr += names+2;
	}

	IPhysicsObject* pObj = GetPhysObject(*ptrNames);
	if(pObj)
	{
		if(m_pSelectedObject)
			m_pSelectedObject->SetRenderState(eNormal);
		m_pSelectedObject = pObj;
		m_pSelectedObject->SetRenderState(eSelected);
	}
}
Any help would be fabbo, ask if any more code is needed to work out what's wrong.

brian
Sep 11, 2001
I obtained this title through beard tax.

That worked great, I can't believe I didn't notice it before. Can't say I know anything about your problem though.

brian
Sep 11, 2001
I obtained this title through beard tax.

It was just what a tutorial was doing, I changed it to 1.0f for the near plane but either way it ran fine.

brian
Sep 11, 2001
I obtained this title through beard tax.

Hey so I was wondering OpenGL how do you go about making a quad with a texture change colour? I want to apply some graphical effects to some sprites by making them flash white and lose opacity but i'm not sure if it's just the texture settings but I can't get it to work. Any help would be fabbo.

edit: Found it through the TexEnv stuff.

brian fucked around with this message at 16:33 on Jun 30, 2009

brian
Sep 11, 2001
I obtained this title through beard tax.

Quick question for anyone who's ever written a software renderer or just understands simple depth sorting in general:

In my software renderer at the moment I have all the meshes push triangles onto a single stack that's then sorted by the centre Z value of the triangle (mean average of vertices), which works great for single objects rendering. The issue arises when there's one object on top of another where some of the triangles in the bottom object are technically closer, like so:


(At the base of the turret thing)

Anyway my question is, is it as simple as just processing sets of triangles per mesh as opposed to all at once (i'd try this without asking but it requires me rethinking how to group stuff up with regards to the scene graph's matrix stack) or is this a more complicated issue? Is this what Z-Fighting is all about?

brian fucked around with this message at 04:09 on Apr 8, 2011

brian
Sep 11, 2001
I obtained this title through beard tax.

Roger dodger thanks chaps, onto Z bufferin'!

brian
Sep 11, 2001
I obtained this title through beard tax.

Is there any good resource for all this? I implemented it in what I can only assume is a terrible manner as while it fixed some of the issues it created similar issues in the back of the scene and slowed down the whole process to 15 from the already low 35 it runs at normally. At the moment i'm just taking the pre-projection camera-space z co-ords and interpolating them for each pixel as I rasterize between the two edges in question. I'm sure I can improve the rasterization method using the Bresenham method someone suggested I can use, but it seems like i'm shooting in the dark when it comes to optimal methods.

Couple that with this just being a quick fun throwaway project if it's going to get insanely complicated for little result i'd rather stick with painter's and just make the game around it. The game itself is going to be a space shooter where you're a stationary turret shooting spaceships so there's unlikely to be a huge issue if I just model the turret base correctly as each ship is unlikely to get close to another and the ones I've done already have had no problems on this front.

brian
Sep 11, 2001
I obtained this title through beard tax.

Thanks for the help with the software rendering everyone, got the Z buffer in after spending 2 days with it not working correctly due to working out the Z wrong because of a stupid mistake involving using edgeZDiff1 instead of edgeZDiff2. Anyway, it seems to be only slightly slower surprisingly, I'm still unsure as to where the bottleneck is in this, flash is kind of bizarre and I haven't done any proper profiling.

brian
Sep 11, 2001
I obtained this title through beard tax.

Hey fellas, I've been doing a rare foray into graphics stuff and I've written a shader for Unity that does palette based textures using a palette indexed picture and a palette texture, it's entirely to do old palette shifting based effects and it's almost definitely horribly inefficient, but it works in a limited capacity but I had to add a constant I don't understand. Anyway here's the shader:

code:
[s][/s]
Shader "Unlit/Palette" 
{
	Properties 
	{
		_MainTex ("Base (Palette Indices)", 2D) = "white" {}
		_PaletteTex ("Palette (RGB)", 2D) = "white" {}
		_PaletteWidth ("Palette Width", Float) = 0
		_PaletteHeight ("Palette Height", Float) = 1
		_PaletteOffset ("Palette Offset", Float) = 0
		_PaletteLength ("Palette Length (all = 0)", Float) = 0
		_TransparentColourIndex ("Transparent Colour Index (-1 for none)", Float) = -1
	}

	SubShader 
	{
		Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
		LOD 100
	
		ZWrite Off
		Blend SrcAlpha OneMinusSrcAlpha 

		Pass 
		{  
			CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag
			
				#include "UnityCG.cginc"

				struct appdata_t {
					float4 vertex : POSITION;
					float2 texcoord : TEXCOORD0;
				};

				struct v2f {
					float4 vertex : SV_POSITION;
					half2 texcoord : TEXCOORD0;
				};

				sampler2D _MainTex;
				sampler2D _PaletteTex;
				float _PaletteWidth;
				float _PaletteHeight;
				float _PaletteOffset;
				float _PaletteLength;
				float _TransparentColourIndex;
				float4 _MainTex_ST;
			
				v2f vert (appdata_t v)
				{
					v2f o;
					o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
					o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
					return o;
				}
			
				fixed4 frag (v2f i) : SV_Target
				{
					float4 col = tex2D(_MainTex, i.texcoord);
					unsigned int palIndex = floor((col.r * 255) + (col.g * 255) + (col.b * 255));

					_PaletteWidth = floor(_PaletteWidth);

					if(_PaletteLength == 0)
						_PaletteLength = _PaletteWidth;

					if(palIndex == floor(_TransparentColourIndex))
						return float4(0,0,0,0);

					float2 palettePosition = float2(((palIndex % floor(_PaletteLength)) + floor(_PaletteOffset)) % _PaletteWidth, 0);

					if(floor(palettePosition.x) == floor(_TransparentColourIndex))
						palettePosition.x = (palettePosition.x + 1) % _PaletteWidth;

					return tex2D(_PaletteTex, float2((palettePosition.x / _PaletteWidth) + 0.01, 0));
				}
			ENDCG
		}
	}
}

(the float inputs and floors are just to use the editor functionality and will go away when I do most of it in scripting)

So I was wondering why I have to add the +0.01 to the x of the tex2D call, if I have it without the +0.01 it misses one of the colours and everything is indexed wrong and I suspect if when I make it support multiple lines of palettes per file for power of 2 textures and whatnot, i'll have to add the same to the y. Any help would be fab.

Also is there a way to get the dimensions of a texture/sampler or do you really have to pass them in each time?

edit: I added support for square palettes and for some reason now I need to subtract 0.01 to the y component of the tex2D call instead of add it, but I still have to add an odd constant that's bound to go wrong when the palette textures gets big and I don't know why :(

brian fucked around with this message at 11:18 on Nov 5, 2014

brian
Sep 11, 2001
I obtained this title through beard tax.

Jewel posted:

Really not quite sure since I haven't given it a good look yet, but remember that things are 0 indexed so you might have to use (length - 1) or (width - 1) somewhere. It sounds like that could be the issue based on past experiences.

Edit: Oh! Also, sampler lookups are on texture edges, not their centers. You have to add half of the width of a pixel to the coord to get the center of the pixel. Something like: curPt -= mod(curPt, (0.5 / vec2(imgW, imgH)));

Ah that explains a lot, does that mean if i'm having to subtract from the y by half a pixel it means that my y indexing is off? It's all so very hard to debug with these things, thanks a bunch though!

Adbot
ADBOT LOVES YOU

brian
Sep 11, 2001
I obtained this title through beard tax.

Jewel posted:

I'd say get your math and put it into python or something and run through it on the cpu and check against manually calculated values to see if you're getting where you should or not (when you get the 0-1 value, multiply it by image width/height and check where that falls on the real image).

Haha I finally worked it out, I was under the assumption that texture coordinates started in the top left for some reason, it worked fine with a texture with only two lines because it wrapped around laffo, it all makes sense now, thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply