• What do you need help with? Version 5
    5,752 replies, posted
You can pretend that it's a normal member unlike with pointers
Oh ok, but I don't think it'll be good for the reference to think that its the normal when in reality it's just a shadow of it's other self which actually occupies space. However I'll keep that in mind.
[QUOTE=ROBO_DONUT;35348373]Draw actual lines, instead? GL_LINE_LOOP will get you an outline around the polygon.[/QUOTE] Using a GL_LINE_LOOP would display lines even where it shouldn't, like where two rectangles overlap, you'd see the internal lines. I'd need to find some way of culling that so I only get the outline formed by the shapes - the method I'm using now does this quite easily but the corners are still annoying. [editline]30th March 2012[/editline] On a related note, anyone have any suggestions for a really lightweight rigid body physics engine?
[QUOTE=mechanarchy;35349308]Using a GL_LINE_LOOP would display lines even where it shouldn't, like where two rectangles overlap, you'd see the internal lines. I'd need to find some way of culling that so I only get the outline formed by the shapes - the method I'm using now does this quite easily but the corners are still annoying.[/QUOTE] Render them as lines first, then render triangles over. Do it with depth testing off. You shouldn't need polygon offset. You can adjust the line width, too, and you probably want to set it to at least 2, so that the outline sticks out some. [QUOTE=mechanarchy;35349308]On a related note, anyone have any suggestions for a really lightweight rigid body physics engine?[/QUOTE] Bullet? I used JBullet on Android, and it was pretty nice. Wait, 2D? Not sure. Box2D maybe?
[QUOTE=ROBO_DONUT;35351903]Render them as lines first, then render triangles over. Do it with depth testing off. You shouldn't need polygon offset. You can adjust the line width, too, and you probably want to set it to at least 2, so that the outline sticks out some.[/QUOTE] I still don't get it. How can I just render them as lines if I have six vertices to define each rectangle (as two triangles)? If I just set the primitive type to GL_LINES it'll only render the top and right sides based on the way I've set up my vertices. Even using GL_LINES or GL_LINE_LOOP I still don't get perfect corners. There's still a pixel missing leaving the corner looking slightly rounded. [QUOTE=ROBO_DONUT;35351903] Bullet? I used JBullet on Android, and it was pretty nice. Wait, 2D? Not sure. Box2D maybe?[/QUOTE] I'll have a look into it.
Geometry shader?
-snip, nevermind. I'm just going to use farseer physics instead-
I'm using the latest snapshot of SFML 2, and I'm trying to implement my own FPS limiter but it's behaving very strangely. I have this at the end of my game loop: [code] sf::Int64 dt = time.getElapsedTime().asMicroseconds(); sf::Int64 excess = (sf::Int64)(1000000.0 / (double)maxFPS) - dt; //maxFPS is 60 by default if(excess > 0) { sf::Clock slept; sf::sleep(sf::microseconds(excess)); sf::Int32 sleptTime = slept.restart().asMilliseconds(); //get the amount of time it actually slept //print that amount std::cout << (sf::Int32)((long)(excess/1000.0) - sleptTime) << std::endl; } time.restart(); [/code] it kind of works, but most of the time it runs at exactly 50fps. The time it spends sleeping is normally about 3ms off the time it's been told to sleep for, but can go up to around 20ms. What could be causing this difference?
[QUOTE=NovembrDobby;35355460]it kind of works, but most of the time it runs at exactly 50fps. The time it spends sleeping is normally about 3ms off the time it's been told to sleep for, but can go up to around 20ms. What could be causing this difference?[/QUOTE] when you sleep, you're telling the operating system to suspend your process for some length of time. Because of the way the OS schedules processes, it can't guarantee that you'll always be scheduled exactly on time.
FPS limiting could be done simply by checking if enough time has passed since the last redraw.
[QUOTE=swift and shift;35355481]when you sleep, you're telling the operating system to suspend your process for some length of time. Because of the way the OS schedules processes, it can't guarantee that you'll always be scheduled exactly on time.[/QUOTE] But it should be pretty close right? I don't know how it can work if the actual sleeping is going to be this inaccurate.
[QUOTE=NovembrDobby;35355745]But it should be pretty close right? I don't know how it can work if the actual sleeping is going to be this inaccurate.[/QUOTE] Why dont you just use the inbuilt SFML fps limiting?
Because it does the same thing, if I tell it to use 60fps it varies between 30 and 100 despite both update() and draw() taking less than 1ms each. This is why I'm trying to make my own.
Case "liters(STP):" always returns a 0, what am I doing wrong?(C#) [code] string moleconvert(string combobox1, string combobox2, string textbox1) { switch (combobox1) { case "moles": switch (combobox2) { case "liters(STP)": double firstunit; bool result = double.TryParse(combobox1, out firstunit); return firstunit.ToString(); default: MessageBox.Show("ERROR!"); return "FAIL"; } default: MessageBox.Show("Error: multiple fields not entered in"); return "FAIL"; } } [/code]
[QUOTE=Cookieeater;35356008]Case "liters(STP):" always returns a 0, what am I doing wrong?(C#) [code] string moleconvert(string combobox1, string combobox2, string textbox1) { switch (combobox1) { case "moles": switch (combobox2) { case "liters(STP)": double firstunit; bool result = double.TryParse(combobox1, out firstunit); return firstunit.ToString(); default: MessageBox.Show("ERROR!"); return "FAIL"; } default: MessageBox.Show("Error: multiple fields not entered in"); return "FAIL"; } } [/code][/QUOTE] Have you tried observing the value of result? double.TryParse will return false if the conversion fails, and I believe by default firstunit will be set to 0. EDIT: I see the bug. You're trying to parse combobox1, which in the outer switch case is determined to be "moles". I think you may have meant [code] double.TryParse(textbox1, out firstunit) [/code]
Javascript: I don't see what I'm doing wrong. In theory, this should be able to detect if an image is png or jpg. [Code]var img = "http://facepunch.com/fp/posticons/release"; var errored = false; var i = new Image(); i.src = img + ".jpg"; i.addEventListener("onerror", function(){errored = true}, false); img = img + (errored ? ".png" : ".jpg");[/Code]
It's setting the img variable before the image has even attempted to load since it isn't fired on a callback. You should set your img variable inside of onload and onerror. e.g. [code] var img = "http://facepunch.com/fp/ratings/tick"; var i = new Image(); i.src = img + ".jpg"; i.onerror = function(){ img += '.png'; } i.onload = function(){ img += '.jpg'; } i.addEventListener("onerror", i.onerror, false); i.addEventListener("onload", i.onload, false); [/code]
[QUOTE=jaybuz;35359790]It's setting the img variable before the image has even attempted to load since it isn't fired on a callback. You should set your img variable inside of onload and onerror. e.g. [code] var img = "http://facepunch.com/fp/ratings/tick"; var i = new Image(); i.src = img + ".jpg"; i.onerror = function(){ img += '.png'; } i.onload = function(){ img += '.jpg'; } i.addEventListener("onerror", i.onerror, false); i.addEventListener("onload", i.onload, false); [/code][/QUOTE] It's always something I overlook. [Img]http://sae.tweek.us/static/images/emoticons/emot-doh.gif[/Img] Thanks.
[QUOTE=vexx21322;35360004]It's always something I overlook. [Img]http://sae.tweek.us/static/images/emoticons/emot-doh.gif[/Img] Thanks.[/QUOTE] You don't actually need to set the event listeners since they're standard. You can remove them.
Can someone help me with this array? What I want to do is basically this: [cpp]#ifndef PROGRAM_HPP_INCLUDED #define PROGRAM_HPP_INCLUDED #include <glm/glm.hpp> #include <glm/gtx/transform2.hpp> #include "./Utilities.hpp" #include "Shader.hpp" class Program { GLfloat g_vertex_buffer_data[108]; public: Program(); ~Program(); void Update(float delta); void Draw(); glm::mat4 Projection; glm::mat4 View; }; #endif // PROGRAM_HPP_INCLUDED[/cpp] [cpp]#include "./Program.hpp" #include "SOIL.h" Program::Program() { View = glm::mat4(1.0); View *= glm::lookAt( glm::vec3(0, 0, 10), // the position of your camera, in world space glm::vec3(0, 0, 0), // where you want to look at, in world space glm::vec3(0, 1, 0) // probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down, which can be great too ); Projection = glm::mat4(1.0); Projection *= glm::perspective( (float)60, // The horizontal Field of View, in degrees : the amount of "zoom". Think "camera lens". Usually between 90° (extra wide) and 30° (quite zoomed in) 1024.0f / 576.0f, // Aspect Ratio. Depends on the size of your window. Notice that 4/3 == 800/600 == 1280/960, sounds familiar ? 0.1f, // Near clipping plane. Keep as big as possible, or you'll get precision issues. 100.0f // Far clipping plane. Keep as little as possible. ); g_vertex_buffer_data = new GLfloat{ -1.0f,-1.0f,-1.0f, // triangle 1 : begin -1.0f,-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, // triangle 1 : end 1.0f, 1.0f,-1.0f, // triangle 2 : begin -1.0f,-1.0f,-1.0f, -1.0f, 1.0f,-1.0f, // triangle 2 : end 1.0f,-1.0f, 1.0f, -1.0f,-1.0f,-1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f,-1.0f, 1.0f,-1.0f,-1.0f, -1.0f,-1.0f,-1.0f, -1.0f,-1.0f,-1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f,-1.0f, 1.0f,-1.0f, 1.0f, -1.0f,-1.0f, 1.0f, -1.0f,-1.0f,-1.0f, -1.0f, 1.0f, 1.0f, -1.0f,-1.0f, 1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f,-1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f, -1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f,-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,-1.0f, 1.0f }; } Program::~Program() { delete [] g_vertex_buffer_data; } void Program::Update(float delta) { } void Program::Draw() { }[/cpp]
How can I test a server client connection with 2 clients and a server both on the same PC? I think one of the clients is hogging all the packets sent by the server, starving the other one.
I'm trying to make a little game in android, but I have a problem with displaying a sprite. [img]http://dl.dropbox.com/u/14515180/artifact.png[/img] The left part of the image is the original sprite and the right is how it's shown in the emulator. As you can see there is a little artifact. Any idea how to fix it ?
Make sure the texture is a power of 2.
[QUOTE=Richy19;35360881]Can someone help me with this array? What I want to do is basically this: [cpp] GLfloat g_vertex_buffer_data[108]; [/cpp] [cpp] g_vertex_buffer_data = new GLfloat { ... } [/cpp] [/QUOTE] You've set g_vertex_buffer_data as a static array of 108 floats. If you want to use dynamic memory management (new and delete) you'll have to store it as GLfloat* instead of GLfloat[108]. I'd recommend switching to new and delete anyway because if you're not absolutely certain you're going to have 36 vertices every time, it's not worth leaving it as it is. All you should need to change is just the one line in the header. [editline]31st March 2012[/editline] [QUOTE=Cyril;35361463]I'm trying to make a little game in android, but I have a problem with displaying a sprite. [t]http://dl.dropbox.com/u/14515180/artifact.png[/t] The left part of the image is the original sprite and the right is how it's shown in the emulator. As you can see there is a little artifact. Any idea how to fix it ?[/QUOTE] It looks like the image is being resized slightly, by a pixel or two, and that's making it look bad. Make sure you're not resizing the image yourself somewhere, and that the image dimensions are both powers of two (says Parad0x0217 - I don't know much about android)
[QUOTE=calzoneman;35356195]Have you tried observing the value of result? double.TryParse will return false if the conversion fails, and I believe by default firstunit will be set to 0. EDIT: I see the bug. You're trying to parse combobox1, which in the outer switch case is determined to be "moles". I think you may have meant [code] double.TryParse(textbox1, out firstunit) [/code][/QUOTE] Wow, what a dumb bug. Thanks.
So I'm taking a crack at making a top down shooter in XNA. I have turning set to the right stick on an xbox controller, here's the code: [code]Player.Angle = -(float)Math.Atan2(rightstick.Y, rightstick.X) + 4.7f;[/code] Now when I release the stick and am not touching it at all, it goes to it's original angle. This makes sense, as the right thumbstick is at position 0, 0. The only way I could thing to fix it is this: [code] if (rightstick.X != 0 && rightstick.Y !=0) { Player.Angle = -(float)Math.Atan2(rightstick.Y, rightstick.X) + 4.7f; } [/code] That didn't work, it then just wouldn't set my angle if I had it directly left/up/right/down, because one of the X,Y positions was 0. What do? :c
[QUOTE=Doctor Dark;35363102]So I'm taking a crack at making a top down shooter in XNA. I have turning set to the right stick on an xbox controller, here's the code: [code]Player.Angle = -(float)Math.Atan2(rightstick.Y, rightstick.X) + 4.7f;[/code] Now when I release the stick and am not touching it at all, it goes to it's original angle. This makes sense, as the right thumbstick is at position 0, 0. The only way I could thing to fix it is this: [code] if (rightstick.X != 0 && rightstick.Y !=0) { Player.Angle = -(float)Math.Atan2(rightstick.Y, rightstick.X) + 4.7f; } [/code] That didn't work, it then just wouldn't set my angle if I had it directly left/up/right/down, because one of the X,Y positions was 0. What do? :c[/QUOTE] Whoops I'm an idiot. Just put rightstick.X != 0 || rightstick.Y != 0
[QUOTE=WTF Nuke;35363168]Whoops I'm an idiot. Just put rightstick.X != 0 || rightstick.Y != 0[/QUOTE] Wow what an easy fix. Thank you, appreciate it.
[QUOTE=mechanarchy;35362675]You've set g_vertex_buffer_data as a static array of 108 floats. If you want to use dynamic memory management (new and delete) you'll have to store it as GLfloat* instead of GLfloat[108]. I'd recommend switching to new and delete anyway because if you're not absolutely certain you're going to have 36 vertices every time, it's not worth leaving it as it is. All you should need to change is just the one line in the header. [/QUOTE] Im only wanting to draw a cube for this project, but what would be the best way to do it(or better said the safest) Doint it the way you meantion gives tis error: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘GLfloat {aka float}’ in initialization| [editline]31st March 2012[/editline] Can anyone see why this doesnt output anything? [cpp]#ifndef PROGRAM_HPP_INCLUDED #define PROGRAM_HPP_INCLUDED #include <glm/glm.hpp> #include <glm/gtx/transform2.hpp> #include "./Utilities.hpp" #include "Shader.hpp" class Program { GLfloat g_vertex_buffer_data[108]; GLuint vertexbuffer; Shader shader; glm::mat4 MVP ; GLuint MatrixID ; public: Program(); ~Program(); void Update(float delta); void Draw(); glm::mat4 Projection; glm::mat4 View; }; #endif // PROGRAM_HPP_INCLUDED [/cpp] [cpp]#include "./Program.hpp" #include "SOIL.h" Program::Program() { shader = Shader("a", "a"); View = glm::mat4(1.0); View *= glm::lookAt( glm::vec3(0, 0, 10), // the position of your camera, in world space glm::vec3(0, 0, 0), // where you want to look at, in world space glm::vec3(0, 1, 0) // probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down, which can be great too ); Projection = glm::mat4(1.0); Projection *= glm::perspective( (float)60, // The horizontal Field of View, in degrees : the amount of "zoom". Think "camera lens". Usually between 90° (extra wide) and 30° (quite zoomed in) 1024.0f / 576.0f, // Aspect Ratio. Depends on the size of your window. Notice that 4/3 == 800/600 == 1280/960, sounds familiar ? 0.1f, // Near clipping plane. Keep as big as possible, or you'll get precision issues. 100.0f // Far clipping plane. Keep as little as possible. ); GLfloat fltarr[108] { -1.0f,-1.0f,-1.0f, // triangle 1 : begin -1.0f,-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, // triangle 1 : end 1.0f, 1.0f,-1.0f, // triangle 2 : begin -1.0f,-1.0f,-1.0f, -1.0f, 1.0f,-1.0f, // triangle 2 : end 1.0f,-1.0f, 1.0f, -1.0f,-1.0f,-1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f,-1.0f, 1.0f,-1.0f,-1.0f, -1.0f,-1.0f,-1.0f, -1.0f,-1.0f,-1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f,-1.0f, 1.0f,-1.0f, 1.0f, -1.0f,-1.0f, 1.0f, -1.0f,-1.0f,-1.0f, -1.0f, 1.0f, 1.0f, -1.0f,-1.0f, 1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f,-1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f, -1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f,-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,-1.0f, 1.0f }; for(int i = 0; i < 108; i++) { g_vertex_buffer_data[i] = fltarr[i]; } // This will identify our vertex buffer // Generate 1 buffer, put the resulting identifier in vertexbuffer glGenBuffers(1, &vertexbuffer); // The following commands will talk about our 'vertexbuffer' buffer glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); // Give our vertices to OpenGL. glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); // Get a handle for our "MVP" uniform. // Only at initialisation time. MatrixID = glGetUniformLocation(shader.shaderID, "MVP"); } Program::~Program() { } void Program::Update(float delta) { // Model matrix : an identity matrix (model will be at the origin) glm::mat4 Model = glm::mat4(1.0f); // Changes for each model ! // Our ModelViewProjection : multiplication of our 3 matrices MVP = Projection * View * Model; // } void Program::Draw() { // Send our transformation to the currently bound shader, // in the "MVP" uniform // For each model you render, since the MVP will be different (at least the M part) // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( 0, // attribute 0. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); glUseProgram(shader.shaderID); glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 12*3); // Starting from vertex 0; 3 vertices total -> 1 triangle glDisableVertexAttribArray(0); } [/cpp] the shaders being: [cpp]std::string Shader::basicVert = "#version 120\n"\ "uniform mat4 MVP;"\ "attribute vec4 Position;"\ "attribute vec2 UV; "\ "varying vec2 uv;"\ "void main(){"\ "uv = UV;"\ "gl_Position = MVP * Position;"\ "}"; std::string Shader::basicFrag = "#version 120\n"\ "varying vec2 uv;"\ "uniform sampler2D myTexture;"\ "void main(){"\ "gl_FragColor = vec4(1,0,0,1);"\ "}";[/cpp]
Can anyone help me with this? I tried to write a function that outputs a hex string from an integer to the screen, but it doesn't seem to be working. [code] void monitor_write_hex(u32int n) { int i; u8int hex_char; for(i = 32; i > 0; i -= 4) { hex_char = (n << i) & 0xF; if(hex_char >= 0xA) monitor_put((hex_char - 0xA) + 'a'); else monitor_put(hex_char + '0'); } } [/code] For monitor_write_hex(256) I get "00000000" on the screen. Any tips?
Sorry, you need to Log In to post a reply to this thread.