• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=Kopimi;36336006]ok i have a pretty stupid issue, i feel like this is polymorphism 101 but i don't know how to solve it: see the following code: [cpp] class Parent { public: Parent(); ~Parent(); virtual void MyFunc(); } Parent::Parent() { MyFunc(); } void Parent::MyFunc() { std::cout << "Parent!" << std::endl; } // -------------------- class Child : public Parent { public: Child(); ~Child(); virtual void MyFunc(); } Child::Child() : Parent() {} void Child::MyFunc() { std::cout << "Child!" << std::endl; } [/cpp] the output of the program ends up as "Parent!", whereas i would expect/hope it to be "Child!" i want a parent class to call the overloaded version of a virtual function, however, the parent class only calls it's own version of the function. what's the dealio?[/QUOTE] Just an extra thing for this, you should use a virtual destructor in your parent class, otherwise your child class may not be destructed correctly. The reason for this is that a non-virtual destructor only knows how to remove things inside the child class, it will not call the parent's destructor to remove things in there as well (which, of course, are technically part of the child class.)
[QUOTE=ROBO_DONUT;36336611]If you're drawing to a fully transparent buffer, then this is wrong. You want glBlendFunc(GL_ONE, GL_ZERO). Or just disable blending altogether.[/QUOTE] Hmm, do you mean using those parameters upon rendering to the target, or when rendering the texture created by the target? I tried both, and it looks different. Seems like the black levels are better, but the white levels are still way off. [IMG]http://i.snag.gy/s7idz.jpg[/IMG] Maybe I'm doing something else wrong? You can see the full RenderTarget class in the [URL="http://pastebin.com/zd9xQW4X"]pastebin[/URL] link I posted if you want to take a peek.
Just trying to get SFML working in Eclipse... what? [img]http://i.imgur.com/OIpjy.png[/img]
[QUOTE=Asgard;36344350]Just trying to get SFML working in Eclipse... what? [img]http://i.imgur.com/OIpjy.png[/img][/QUOTE] See eclipse just looks cooler on Linux.
[QUOTE=Asgard;36344350]Just trying to get SFML working in Eclipse... what? [img]http://i.imgur.com/OIpjy.png[/img][/QUOTE] Are you mixing SFML versions? sf::Text only exists in SFML 2.0, but only the sf::Drawable of 1.6 has a virtual void Render(RenderTarget& Target) method.
I'm new to C++, but is there a way to have something run every five seconds without it stopping the rest of the program from running? I'm assuming this will have something to do with threads.
[QUOTE=Mordi;36341904]Hmm, do you mean using those parameters upon rendering to the target, or when rendering the texture created by the target? I tried both, and it looks different. Seems like the black levels are better, but the white levels are still way off.[/QUOTE] Did you stop and think about it a bit? What the blending is actually doing? You want blending enabled if you're drawing a partially transparent object onto an opaque background, since the destination color actually matters. You do not want blending enabled if you're drawing a partially transparent object onto a fully transparent background because the background color (which shouldn't be visible) will leak into the final color because the blend function doesn't take destination alpha into consideration. OpenGL provides destination alpha enums for the blend function, but it isn't supported by some hardware and other hardware only supports it for certain image formats, so it's generally best to just avoid destination alpha altogether. So draw the text to the FBO without blending, then draw the FBO to the screen with blending. This is, of course, assuming that the FBO or 'render target' is actually transparent before you start drawing the glyphs. You haven't explicitly stated this, but I'm guessing this is the case because it would cause the results you're seeing. If this is not the case, then you're going to have to explain the situation to me again.
[QUOTE=dajoh;36336164]Only works that way outside of the class, not inside.[/QUOTE] it works anywhere except the Parent constructor this code outputs "parent child child" [cpp] class Parent { public: Parent(); void what() { MyFunc(); } virtual void MyFunc(); }; Parent::Parent() { MyFunc(); } void Parent::MyFunc() { std::cout << "Parent!" << std::endl; } // -------------------- class Child : public Parent { public: Child(); virtual void MyFunc(); }; Child::Child() : Parent() {} void Child::MyFunc() { std::cout << "Child!" << std::endl; } int main() { Child c; c.MyFunc(); c.what(); } [/cpp]
[QUOTE=Chessnut;36346459]I'm new to C++, but is there a way to have something run every five seconds without it stopping the rest of the program from running? I'm assuming this will have something to do with threads.[/QUOTE] If you want the thing you want repeated not to interfere with the rest of the application, then yes. Or else you could use the main loop and check if there's been 5 seconds since the last time it ran.
[QUOTE=Swebonny;36324459]Well, as a beginner project you could try to make some bouncing balls on a two dimensional horizontal surface. You would then hopefully learn how to create shapes, how to change their position, how to use classes and create classes(if you want to make a ball class). You'd also use conditional statements to check where it will hit and so on.[/QUOTE] Done :v:
[QUOTE=ROBO_DONUT;36346650] So draw the text to the FBO without blending, then draw the FBO to the screen with blending. This is, of course, assuming that the FBO or 'render target' is actually transparent before you start drawing the glyphs. You haven't explicitly stated this, but I'm guessing this is the case because it would cause the results you're seeing. If this is not the case, then you're going to have to explain the situation to me again.[/QUOTE] This is how the FBO is created: [cpp]// Create and initialize framebuffer texRT = new GLuint[texCount]; glGenFramebuffers(1, &frameBufferRT); glBindFramebuffer(GL_FRAMEBUFFER, frameBufferRT); glGenTextures(texCount, texRT); for(int i = 0; i < texCount; i ++) { glBindTexture(GL_TEXTURE_2D, texRT[i]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, texRT[i], 0); } glBindFramebuffer(GL_FRAMEBUFFER, 0); [/cpp] The FBO is transparent when I render stuff onto it. I clear it before rendering like so: [cpp]// Clear the buffer glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT);[/cpp] I attempted to disable blending before rendering, and then enabling afterwards. The black-levels are better, but full-white pixels appear transparent.
Ok, so I've got a vbo working now thanks to the help of robmaister12, but now I'm wondering how I'm supposed to get textures working. Before, I used GL.Begin and GL.End, allowing me to change textures between each face and thereby giving each face the right texture. Now that I'm using a vbo there's no way for me to get in there and change the texture so I'm pretty much stuck with 1 texture. Code: [csharp] GL.BindBuffer( BufferTarget.ArrayBuffer, vbo ); GL.VertexPointer( 3, VertexPointerType.Float, 32, 0 ); GL.TexCoordPointer( 2, TexCoordPointerType.Float, 32, 12 ); GL.NormalPointer( NormalPointerType.Float, 32, 20 ); GL.DrawArrays( BeginMode.Triangles, 0, verticesCount ); // I'd like to change the texture somehow between each face call in here. GL.BindBuffer( BufferTarget.ArrayBuffer, 0 ); [/csharp] I'm doing this in C# with OpenTK. Any help is appreciated!
How to move object to direction? [cpp] private float x, y; private float speed = 1; private int rotation; public void draw(GL10 gl) { rotation+=1; if(rotation>360) rotation = 0; x+=sin(rotation)*speed; y+=cos(rotation)*speed; gl.glPushMatrix(); gl.glTranslatef(x,y,0); gl.glRotatef(rotation,0,0,1); // Draw object... gl.glPopMatrix(); } [/cpp] makes it look wierd.
[QUOTE=xThaWolfx;36367647]Ok, so I've got a vbo working now thanks to the help of robmaister12, but now I'm wondering how I'm supposed to get textures working. Before, I used GL.Begin and GL.End, allowing me to change textures between each face and thereby giving each face the right texture. Now that I'm using a vbo there's no way for me to get in there and change the texture so I'm pretty much stuck with 1 texture. Code: [csharp] GL.BindBuffer( BufferTarget.ArrayBuffer, vbo ); GL.VertexPointer( 3, VertexPointerType.Float, 32, 0 ); GL.TexCoordPointer( 2, TexCoordPointerType.Float, 32, 12 ); GL.NormalPointer( NormalPointerType.Float, 32, 20 ); GL.DrawArrays( BeginMode.Triangles, 0, verticesCount ); // I'd like to change the texture somehow between each face call in here. GL.BindBuffer( BufferTarget.ArrayBuffer, 0 ); [/csharp] I'm doing this in C# with OpenTK. Any help is appreciated![/QUOTE] There are two approaches you can take here. If you have a discrete set of textures with a lot of texture changes (e.g. Minecraft) you can have a texture atlas. A texture atlas is a texture with all textures in it, so you don't have to switch textures anymore. You just have to change the texture coordinates. Otherwise, you'll have to switch textures and then call the draw command for one specific object again and again. This is more common in regular games where each model has its own texture.
[QUOTE=Overv;36368416]There are two approaches you can take here. If you have a discrete set of textures with a lot of texture changes (e.g. Minecraft) you can have a texture atlas. A texture atlas is a texture with all textures in it, so you don't have to switch textures anymore. You just have to change the texture coordinates. Otherwise, you'll have to switch textures and then call the draw command for one specific object again and again. This is more common in regular games where each model has its own texture.[/QUOTE] Well, the problem is that my model has multiple textures. It's the improved Sponza Atrium model found [url=http://graphics.cs.williams.edu/data/meshes.xml]here[/url]. So it's not one model with one texture, but one model with several textures.
[QUOTE=xThaWolfx;36368606]Well, the problem is that my model has multiple textures. It's the improved Sponza Atrium model found [url=http://graphics.cs.williams.edu/data/meshes.xml]here[/url]. So it's not one model with one texture, but one model with several textures.[/QUOTE] Yes, but the model consists of several parts each with a texture assigned to it.
[QUOTE=Overv;36368898]Yes, but the model consists of several parts each with a texture assigned to it.[/QUOTE] Which translates into: Split the mesh up into multiple draw calls, by material.
[QUOTE=Lord Ned;36369015]Which translates into: Split the mesh up into multiple draw calls, by material.[/QUOTE] Thanks to both you and Overv, I've managed to fix it!
When I call wglGetExtensionsStringARB, what free functions should I use afterwards. I was thinking GlobalFree since it would make sense for OpenGL to allocate with GlobalAlloc to map it to the default process heap.
You're not supposed to clean it up yourself. OpenGL will leave the memory allocation up to you when that is necessary, as seen with functions like glGetShaderInfoLog.
[QUOTE=Overv;36370340]You're not supposed to clean it up yourself. OpenGL will leave the memory allocation up to you when that is necessary, as seen with functions like glGetShaderInfoLog.[/QUOTE] So what? It just stays in memory forever or for as long as the context is around?
[QUOTE=flayne;36376072]So what? It just stays in memory forever or for as long as the context is around?[/QUOTE] That is implementation dependent, you don't have to worry about it.
Sorry for the crappy image, but Printscreen/Puush doesn't capture the mouse cursor. [img]http://yfrog.com/hsnhbncj:iphone[/img] I'm using the following code in XNA: [code] MouseState ms = Mouse.GetState(); protected override void Initialize() { graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; graphics.IsFullScreen = false; graphics.ApplyChanges(); Window.Title = "Kuub"; this.IsMouseVisible = true; Mouse.SetPosition(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2); } combined with spriteBatch.Draw(WhiteTexture, new Rectangle(ms.X - 1, ms.Y - 1, 2, 2), Color.Black); [/code] As you can see, they are offset for some reason. The distance stays the same. The position seems to be different each time the game is run, probably because of the position of the mouse when the game is start. Anyone have an idea?
Is there any reason why sf::renderTexture is flipping my image vertically?
I currently have a funnction to tell if a key is pressed, but im trying to have a function to tell if the keypress is new(AKA it wasnt pressed in the previous frame) So my keyboard function has an enum with all keys, and a bool array set to false as so: [CODE]bool SOGLF::Keyboard::wasKeyPressed[Count] = {false};[/CODE] so if a key is true it means it was pressed in the previous frame It then has getter and setter for the array: [CODE]void SOGLF::Keyboard::SetWasKeyDown(SOGLF::Keyboard::Keys key, bool b) { SOGLF::Keyboard::wasKeyPressed[(int)key] = b; } bool SOGLF::Keyboard::WasKeyDown(SOGLF::Keyboard::Keys key) { return SOGLF::Keyboard::wasKeyPressed[((int)key)]; }[/CODE] Aswell as a function to return if its a new press: bool SOGLF::Keyboard::NewKeyPress(SOGLF::Keyboard::Keys key) { return ( !WasKeyDown(key) && IsKeyDown(key)); } Now in my controlls method I update it all via: [CODE]for(int i = 0; i < SOGLF::Keyboard::Count; i++) { if(SOGLF::Keyboard::WasKeyDown((SOGLF::Keyboard::Keys)i)) { if(!SOGLF::Keyboard::IsKeyDown( (SOGLF::Keyboard::Keys)i )) { SOGLF::Keyboard::SetWasKeyDown((SOGLF::Keyboard::Keys)i, false); } } else { if(SOGLF::Keyboard::IsKeyDown( (SOGLF::Keyboard::Keys)i )) { SOGLF::Keyboard::SetWasKeyDown((SOGLF::Keyboard::Keys)i, true); } } }[/CODE] But for some reason it isnt working, can anyone see anything obvious?
[QUOTE=Richy19;36381709]I currently have a funnction to tell if a key is pressed, but im trying to have a function to tell if the keypress is new(AKA it wasnt pressed in the previous frame) So my keyboard function has an enum with all keys, and a bool array set to false as so: [CODE]bool SOGLF::Keyboard::wasKeyPressed[Count] = {false};[/CODE] so if a key is true it means it was pressed in the previous frame It then has getter and setter for the array: [CODE]void SOGLF::Keyboard::SetWasKeyDown(SOGLF::Keyboard::Keys key, bool b) { SOGLF::Keyboard::wasKeyPressed[(int)key] = b; } bool SOGLF::Keyboard::WasKeyDown(SOGLF::Keyboard::Keys key) { return SOGLF::Keyboard::wasKeyPressed[((int)key)]; }[/CODE] Aswell as a function to return if its a new press: bool SOGLF::Keyboard::NewKeyPress(SOGLF::Keyboard::Keys key) { return ( !WasKeyDown(key) && IsKeyDown(key)); } Now in my controlls method I update it all via: [CODE]for(int i = 0; i < SOGLF::Keyboard::Count; i++) { if(SOGLF::Keyboard::WasKeyDown((SOGLF::Keyboard::Keys)i)) { if(!SOGLF::Keyboard::IsKeyDown( (SOGLF::Keyboard::Keys)i )) { SOGLF::Keyboard::SetWasKeyDown((SOGLF::Keyboard::Keys)i, false); } } else { if(SOGLF::Keyboard::IsKeyDown( (SOGLF::Keyboard::Keys)i )) { SOGLF::Keyboard::SetWasKeyDown((SOGLF::Keyboard::Keys)i, true); } } }[/CODE] But for some reason it isnt working, can anyone see anything obvious?[/QUOTE] I just woke up so I'm a little too sleepy to read through your code, but I've already implemented the same thing in my game. And mine doesn't need to check every key every frame either. You can check it out [url=https://github.com/naelstrof/Astrostruct/blob/master/src/NInput.cpp]here[/url] (line 24), and as always you can ask me questions about it on steam.
[QUOTE=Jimmylaw;36381640]Is there any reason why sf::renderTexture is flipping my image vertically?[/QUOTE] That's because OpenGL's coordinate system has ( 0, 0 ) in the [b]bottom[/b]-left corner. You'll have to account for that yourself.
When creating a model for OpenGL what coordinate range should I use? Should I make all of my vertices coordinates be in the -1, 1 range or should I use higher floats? This is assuming I typically want to use matrices without having to have scale right of the bat.
So today I've learnt the importance of a rich dataset. I can't expect a learning algorithm to learn something with a set of inputs which always have the same output, it'll just always assume the solution to be 1.0, even if the image actually is wrong. But it was always correct for the training set. So now I need to add some images to my training set which isn't the character the cell is looking for.
[QUOTE=Naelstrom;36382521]I just woke up so I'm a little too sleepy to read through your code, but I've already implemented the same thing in my game. And mine doesn't need to check every key every frame either. You can check it out [url=https://github.com/naelstrof/Astrostruct/blob/master/src/NInput.cpp]here[/url] (line 24), and as always you can ask me questions about it on steam.[/QUOTE] The problem is, before i was just checking if the key is down, but at 200fps it just kept swapping(as in the console display kept swapping as I cant remove my finger fast enought) so im trying to tell if the key has been pressed just once or if the key is held, to have things like text input or toggle stuff No worries got it working :DD Does anyone know what source file lua defines the print function in? I want to re-write it to output it to the in-game console
Sorry, you need to Log In to post a reply to this thread.