• What do you need help with? Version 5
    5,752 replies, posted
When doing Love2D stuff, does every function have to be a member function of love? (love.xxxx ())
C# + Microsoft excel question: Is it possible to add a module/macro into an excel sheet using c#? I need to create something like this: A console program, that adds a macro to all excel sheets in the same folder.
If I have this array: [cpp] Block* chunk[16][16][16]; for(int z = 0; z < 16; z++) for(int y = 0; y < 16; y++) for(int x = 0; x < 16; x++) chunk[z][y][x] = new Block(); [/cpp] is this the correct way to delete the array? [cpp] for(int z = 0; z < 16; z++) { for(int y = 0; y < 16; y++) { delete[] chunk[z][y]; } delete[] chunk[z]; } delete[] chunk;[/cpp] it gave me memory errors so instead I just : [cpp] for(int z = 0; z < 16; z++) { for(int y = 0; y < 16; y++) { for(int x = 0; x < 16; x++) { delete chunk[z][y][x]; chunk[z][y][x] = NULL; } } }[/cpp]
Another problem, I realize theres lots of code but if anyone can have a look it would be much appreciated: Block header: [cpp] #ifndef BLOCK_HPP_INCLUDED #define BLOCK_HPP_INCLUDED #include <GL/glew.h> #include <SOGLF.hpp> #include <glm/glm.hpp> #include <vector> struct Side { SOGLF::Triangle tri[2]; void setTri(int t, const SOGLF::Triangle &tr) { tri[t] = tr; } }; class Block { public: enum Sides { Front, Right, Back, Left, Top, Bottom }; protected: Side sides[6]; unsigned char TextureID; glm::vec3 Position; public: Block(); Block(const glm::vec3 &pos, float scale); ~Block(); const Side &getSide(Sides s); }; #endif // BLOCK_HPP_INCLUDED [/cpp] Block cpp [cpp] #include "Block.hpp" Block::Block() {} Block::Block(const glm::vec3 &pos, float scale) { Position = pos; TextureID = 0; float hscale = scale / 2.0f; SOGLF::Vertex v[8]; v[0] = SOGLF::Vertex( glm::vec3( pos.x - hscale, pos.y - hscale, pos.z + hscale ) , glm::vec2(0.0, 0.0) , glm::vec3(0.0) ); v[1] = SOGLF::Vertex( glm::vec3( pos.x - hscale, pos.y + hscale, pos.z + hscale ) , glm::vec2(0.0, 0.0) , glm::vec3(0.0) ); v[2] = SOGLF::Vertex( glm::vec3( pos.x + hscale, pos.y + hscale, pos.z + hscale ) , glm::vec2(0.0, 0.0) , glm::vec3(0.0) ); v[3] = SOGLF::Vertex( glm::vec3( pos.x + hscale, pos.y - hscale, pos.z + hscale ) , glm::vec2(0.0, 0.0) , glm::vec3(0.0) ); v[4] = SOGLF::Vertex( glm::vec3( pos.x + hscale, pos.y - hscale, pos.z - hscale ) , glm::vec2(0.0, 0.0) , glm::vec3(0.0) ); v[5] = SOGLF::Vertex( glm::vec3( pos.x + hscale, pos.y + hscale, pos.z - hscale ) , glm::vec2(0.0, 0.0) , glm::vec3(0.0) ); v[6] = SOGLF::Vertex( glm::vec3( pos.x - hscale, pos.y + hscale, pos.z - hscale ) , glm::vec2(0.0, 0.0) , glm::vec3(0.0) ); v[7] = SOGLF::Vertex( glm::vec3( pos.x - hscale, pos.y - hscale, pos.z - hscale ) , glm::vec2(0.0, 0.0) , glm::vec3(0.0) ); SOGLF::Triangle t[12]; t[0] = SOGLF::Triangle(v[0], v[1], v[3]); t[1] = SOGLF::Triangle(v[3], v[1], v[2]); t[2] = SOGLF::Triangle(v[3], v[2], v[4]); t[3] = SOGLF::Triangle(v[4], v[2], v[5]); t[4] = SOGLF::Triangle(v[4], v[5], v[7]); t[5] = SOGLF::Triangle(v[7], v[5], v[6]); t[6] = SOGLF::Triangle(v[7], v[6], v[0]); t[7] = SOGLF::Triangle(v[0], v[6], v[1]); t[8] = SOGLF::Triangle(v[7], v[0], v[4]); t[9] = SOGLF::Triangle(v[4], v[0], v[3]); t[10] = SOGLF::Triangle(v[1], v[6], v[2]); t[11] = SOGLF::Triangle(v[2], v[6], v[5]); for(int i = 0; i < 12; i++) sides[ (i/2) ].setTri( (i%2), SOGLF::Triangle(t[i]) ); } Block::~Block() { } const Side &Block::getSide(Sides s) { return sides[s]; } [/cpp] Chunk header [cpp] #ifndef CHUNK_HPP_INCLUDED #define CHUNK_HPP_INCLUDED #include "Block.hpp" #include "soglf/Texture.hpp" #include "soglf/Drawable.hpp" #include "soglf/Shader.hpp" struct BlockSidesIndices { int F, L,B, R, T, Bot; int F2, L2,B2, R2, T2, Bot2; }; class Chunk { Block* chunk[16][16][16]; GLuint vertexbuffer; GLuint uvbuffer; GLuint normalbuffer; GLuint indexbuffer; std::vector<glm::vec3> PosList; std::vector<glm::vec2> UVList; std::vector<glm::vec3> NormList; std::vector<GLuint> IndexList; std::vector<BlockSidesIndices> chunkBlockIndex; SOGLF::Texture bitmap; SOGLF::Shader shader; glm::mat4 MVP; GLuint TextureID; GLuint NormalsID; GLuint MVPID; GLuint PositionID; GLuint UVID; GLuint DrawLinesID; public: Chunk(); ~Chunk(); void Recompute(); void Draw(); }; #endif // CHUNK_HPP_INCLUDED [/cpp] chunk cpp [cpp] #include "Chunk.hpp" Chunk::Chunk() { shader = SOGLF::Shader("./basic.vert" , "./basic.frag"); MVPID = glGetUniformLocation(shader.GetShaderID(), "MVP"); TextureID = glGetUniformLocation(shader.GetShaderID(), "Texture"); DrawLinesID = glGetUniformLocation(shader.GetShaderID(), "DrawLines"); PositionID = glGetAttribLocation(shader.GetShaderID(), "Position"); UVID = glGetAttribLocation(shader.GetShaderID(), "UV"); NormalsID = glGetAttribLocation(shader.GetShaderID(), "Normals"); for(int z = 0; z < 16; z++) { for(int y = 0; y < 16; y++) { for(int x = 0; x < 16; x++) { chunk[z][y][x] = new Block(glm::vec3( x - 8, y-8, z-8 ) , 1.0f); for(int i = 0; i < 6; i++) { Side s = chunk[z][y][x]->getSide( (Block::Sides)i ); SOGLF::Triangle tri1 = s.tri[0]; SOGLF::Triangle tri2 = s.tri[1]; PosList.push_back(tri1.vertex[0].Position); PosList.push_back(tri1.vertex[1].Position); PosList.push_back(tri1.vertex[2].Position); PosList.push_back(tri2.vertex[0].Position); PosList.push_back(tri2.vertex[1].Position); PosList.push_back(tri2.vertex[2].Position); UVList.push_back(tri1.vertex[0].UV); UVList.push_back(tri1.vertex[1].UV); UVList.push_back(tri1.vertex[2].UV); UVList.push_back(tri2.vertex[0].UV); UVList.push_back(tri2.vertex[1].UV); UVList.push_back(tri2.vertex[2].UV); NormList.push_back(tri1.vertex[0].Normal); NormList.push_back(tri1.vertex[1].Normal); NormList.push_back(tri1.vertex[2].Normal); NormList.push_back(tri2.vertex[0].Normal); NormList.push_back(tri2.vertex[1].Normal); NormList.push_back(tri2.vertex[2].Normal); } int currBlock = x + (y + z * 16) * 16; BlockSidesIndices bsi; bsi.F = currBlock + 0; bsi.F = currBlock + 1; bsi.R = currBlock + 2; bsi.R = currBlock + 3; bsi.B = currBlock + 4; bsi.B = currBlock + 5; bsi.L = currBlock + 6; bsi.L = currBlock + 7; bsi.T = currBlock + 8; bsi.T = currBlock + 9; bsi.Bot = currBlock + 10; bsi.Bot = currBlock + 11; chunkBlockIndex.push_back(bsi); } } } glGenBuffers(1, &vertexbuffer); glGenBuffers(1, &uvbuffer); glGenBuffers(1, &normalbuffer); glGenBuffers(1, &indexbuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glBufferData(GL_ARRAY_BUFFER, PosList.size() * sizeof(glm::vec3), &PosList[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, uvbuffer); glBufferData(GL_ARRAY_BUFFER, UVList.size() * sizeof(glm::vec2), &UVList[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, normalbuffer); glBufferData(GL_ARRAY_BUFFER, NormList.size() * sizeof(glm::vec3), &NormList[0], GL_STATIC_DRAW); Recompute(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexbuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, IndexList.size() * sizeof(GLuint), &IndexList[0], GL_STATIC_DRAW); } Chunk::~Chunk() { glDeleteBuffers(1, &vertexbuffer); glDeleteBuffers(1, &uvbuffer); glDeleteBuffers(1, &normalbuffer); glDeleteBuffers(1, &indexbuffer); for(int z = 0; z < 16; z++) { for(int y = 0; y < 16; y++) { for(int x = 0; x < 16; x++) { delete chunk[z][y][x]; chunk[z][y][x] = NULL; } } } } void Chunk::Recompute() { for(int z = 0; z < 16; z++) { for(int y = 0; y < 16; y++) { for(int x = 0; x < 16; x++) { BlockSidesIndices currBlock = chunkBlockIndex[(x + (y + z * 16) * 16)]; if(chunk[z][y][x] != NULL) { if( z == 0 ) { IndexList.push_back(currBlock.B ); IndexList.push_back(currBlock.B2 ); } if( z == 15 ) { IndexList.push_back(currBlock.F ); IndexList.push_back(currBlock.F2 ); } if( y == 0 ) { IndexList.push_back(currBlock.T ); IndexList.push_back(currBlock.T2 ); } if( y == 15 ) { IndexList.push_back(currBlock.Bot ); IndexList.push_back(currBlock.Bot2 ); } if( x == 0 ) { IndexList.push_back(currBlock.L ); IndexList.push_back(currBlock.L2 ); } if( x == 15 ) { IndexList.push_back(currBlock.R ); IndexList.push_back(currBlock.R2 ); } if( z > 0 ) { if(chunk[z-1][y][x] == NULL) { IndexList.push_back(currBlock.B ); IndexList.push_back(currBlock.B2 ); } } if( z < 15 ) { if(chunk[z+1][y][x] == NULL) { IndexList.push_back(currBlock.F ); IndexList.push_back(currBlock.F2 ); } } if( y > 0 ) { if(chunk[z][y-1][x] == NULL) { IndexList.push_back(currBlock.T ); IndexList.push_back(currBlock.T2 ); } } if( y < 15 ) { if(chunk[z][y+1][x] == NULL) { IndexList.push_back(currBlock.Bot ); IndexList.push_back(currBlock.Bot2 ); } } if( x > 0 ) { if(chunk[z][y][x-1] == NULL) { IndexList.push_back(currBlock.L ); IndexList.push_back(currBlock.L2 ); } } if( x < 15 ) { if(chunk[z][y][x+1] == NULL) { IndexList.push_back(currBlock.R ); IndexList.push_back(currBlock.R2 ); } } } } } } } void Chunk::Draw() { glm::mat4 Model = glm::translate(glm::mat4(1.0f), 0.0f , 0.0f, 20.0f); MVP = SOGLF::Matrices::Matrix.GetProjection() * SOGLF::Matrices::Matrix.Camera * Model; shader.Bind(); glUniformMatrix4fv(MVPID, 1, GL_FALSE, &MVP[0][0]); glActiveTexture(GL_TEXTURE0); bitmap.Bind(); glUniform1i(TextureID, 0); glEnableVertexAttribArray(PositionID); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( PositionID, // 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 ); glEnableVertexAttribArray(UVID); glBindBuffer(GL_ARRAY_BUFFER, uvbuffer); glVertexAttribPointer( UVID, // attribute 0. No particular reason for 0, but must match the layout in the shader. 2, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); glEnableVertexAttribArray(NormalsID); glBindBuffer(GL_ARRAY_BUFFER, normalbuffer); glVertexAttribPointer( NormalsID, // 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 ); // Index buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexbuffer); // Draw the triangles ! glDrawElements( GL_TRIANGLES, // mode IndexList.size(), // count GL_UNSIGNED_INT, // type (void*)0 // element array buffer offset ); glDisableVertexAttribArray(NormalsID); glDisableVertexAttribArray(UVID); glDisableVertexAttribArray(PositionID); SOGLF::Texture::Unbind(); SOGLF::Shader::Unbind(); } [/cpp] It compiles and runs fine, but nothing is drawn. The index and vertex lists have the correct number of elements
so im working on a top down zombie city simulation thing in java, and im trying to keep all the entities in a single arraylist. now i have a class called entity and a class that extends entity called zombie and one that extends them called wall. how would i store store both the walls and the zombies in the same arraylist?
[QUOTE=Number-41;36107916]When doing Love2D stuff, does every function have to be a member function of love? (love.xxxx ())[/QUOTE] uh, no. [URL="https://love2d.org/wiki/love"]Only these.[/URL] Don't add to love.x.
So I'm re-learning VB. (I'll move on to C# or C++ eventually) and need some quick help. I have a login form, and when I enter Admin as the username and password as the password, I want to login form to close and form1 to open. Easy right? I thought so, but when I try it out, the whole program closes. If I take Me.Close out, it works fine, but I want it to close. Here's what I have [IMG]http://content.screencast.com/users/Ohfoohy/folders/Jing/media/af8d7777-8d2c-4df3-8a4a-9c021a354fbb/2012-05-28_2246.png[/IMG] I don't have any kind of fancy user database, but if that's possible, it would be nice to know how to make. Also, how do I go about making a database type of thing? What I want is to make a storage area for inputs. For example, when I hit the "correct!" button, I want $300 stored in one spot, and split into 2 other spots; The one spot would just keep track of all the total deposits, the other two spots would be checking and savings, I want that 300 to get split up so that 40% goes to checking and 60% goes to savings. Ya feel me? Any help on either of these will be appreciated.
[QUOTE=Richy19;36111346]Another problem, I realize theres lots of code but if anyone can have a look it would be much appreciated: ... It compiles and runs fine, but nothing is drawn. The index and vertex lists have the correct number of elements[/QUOTE] Try introducing a vertex array object. You would generate it in the chunk constructor and bind it in the draw function.
were is a good place to start learning openGL for C++, i wanna start making some 3d projects but i dont wanna have to port DirectX code
[QUOTE=Kybalt;36111388]so im working on a top down zombie city simulation thing in java, and im trying to keep all the entities in a single arraylist. now i have a class called entity and a class that extends entity called zombie and one that extends them called wall. how would i store store both the walls and the zombies in the same arraylist?[/QUOTE] If it's the same project as the one you showed in WAYWO, which appears to be grid based, why not store the world as a 2D array. Each element of the array can be null, a zombie or a wall, so you can use Entity[][] as the array type.
[QUOTE=Ohfoohy;36115318]So I'm re-learning VB. (I'll move on to C# or C++ eventually) and need some quick help. I have a login form, and when I enter Admin as the username and password as the password, I want to login form to close and form1 to open. Easy right? I thought so, but when I try it out, the whole program closes. If I take Me.Close out, it works fine, but I want it to close. Here's what I have [IMG]http://content.screencast.com/users/Ohfoohy/folders/Jing/media/af8d7777-8d2c-4df3-8a4a-9c021a354fbb/2012-05-28_2246.png[/IMG] I don't have any kind of fancy user database, but if that's possible, it would be nice to know how to make. Also, how do I go about making a database type of thing? What I want is to make a storage area for inputs. For example, when I hit the "correct!" button, I want $300 stored in one spot, and split into 2 other spots; The one spot would just keep track of all the total deposits, the other two spots would be checking and savings, I want that 300 to get split up so that 40% goes to checking and 60% goes to savings. Ya feel me? Any help on either of these will be appreciated.[/QUOTE] project options > untick "End when first form closes" tickbox [editline]29th May 2012[/editline] oh wait its a drop down "Shutdown mode" > when first form closes change it to When last form closes [editline]29th May 2012[/editline] [cpp] Public Class Form1 Dim AvailableCash As Integer Dim PotChecking As Integer Dim PotSavings As Integer Private Sub btnCorrect_Click(sender As System.Object, e As System.EventArgs) Handles btnCorrect.Click PotSavings += 0.6 * AvailableCash PotChecking += 0.4 * AvailableCash End Sub Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load AvailableCash = 300 End Sub End Class [/cpp]
i'm messing around with XNA. [code]FrameRateCounterFont = contentManager.Load<SpriteFont>("Fonts/frameRateCounterFont");[/code] this gives me "Error loading "Fonts\frameRateCounterFont". File not found." the file is there, i can see it. something is buggered with the directory, how can i fix it? or rather, where is the content directory specified?
[QUOTE=twoski;36122808]i'm messing around with XNA. [code]FrameRateCounterFont = contentManager.Load<SpriteFont>("Fonts/frameRateCounterFont");[/code] this gives me "Error loading "Fonts\frameRateCounterFont". File not found." the file is there, i can see it. something is buggered with the directory, how can i fix it? or rather, where is the content directory specified?[/QUOTE] I'm not sure what they've done to it since XNA 3.1, but you should have a content project set up somewhere in your solution. You can add files/folders to that and load them using your content manager. [editline]29th May 2012[/editline] [img]http://www.flatredball.com/frb/docs/images/f/fd/SongInContentProject.png[/img]
My content manager is a separate project in the solution. I was copying how they did it in some examples i looked at. Should i simply include my content manager in the same project? at any rate, the way it is currently set up should have no problems... the content folder is set properly so there should be no problems :/ [img_thumb]http://i.imgur.com/sGWqQ.png[/img_thumb]
Change forward slash to a double backslash
Hey guys. So I decided to try the Win32 API for C++ again. I decided to use the [url=http://msdn.microsoft.com/en-us/library/bb384843.aspx]MSDN's tutorial[/url] on it. I was able to get it to compile fine, but I am getting the message box that the RegisterClassEx's failure triggers (IE I am getting a message box saying "Call to RegisterClassEx failed!" I currently have my WndProc function simply returning 0, because I just wanted to see if I could get this much to work. Note that the "compile with: /D_UNICODE /DUNICODE /DWIN32 /D_WINDOWS /c" in the comments at the top of the full-code sample at the bottom, I don't know exactly what it wants me to do with that, if that's part of the problem. Here's the [url=http://pastebin.com/CcFuEbnX]full code I am using[/url], if anyone wants to see it.
I'm having trouble finding information on Try/Catch in Java. Anyone think they could tell me how to use it to catch someone entering something that is not an integer?
[QUOTE=Jookia;36098068]I've hacked with Desura and I've used HOLLY to make a Fraps thing all using LD_LIBRARY_PATH, would you mind sharing the shell script you're launching, the directory structure, the library filenames, outputs, etc. Just anything that would help.[/QUOTE] Ok, here's some stuff: executable location: /home/dobby/Desktop/Rotion/Release/ ("Rotion" is the filename) My shell script that runs the game properly, /home/dobby/Desktop/Rotion/Release/run.sh: [code] #!/bin/sh DIR="$(dirname $(readlink -f $0))" echo -n "\033]0;Rotion\007" export LD_LIBRARY_PATH="$DIR/libs":$LD_LIBRARY_PATH exec $DIR/Rotion $* [/code] Next to the executable there's the libs folder, containing the SFML libs: libsfml-graphics.so.2.0 etc. [url=http://i.imgur.com/1XERv.png]Full list here.[/url] Running the executable directly seems to do nothing, I assume it's silently erroring since running it from a terminal gives me this: [img]http://i.imgur.com/WZxVc.png[/img] I tried moving the libs into the same folder, no luck. It'd be too messy for my liking anyway. [editline]30th May 2012[/editline] I don't think this'll matter for Desura since they all seem to launch via a shell script anyway, but it'd still be nice to have.
[QUOTE=NovembrDobby;36131881]I tried moving the libs into the same folder, no luck.[/QUOTE] The current directory should never be in LD_LIBRARY_PATH by default anyway, why would you even consider trying?
[QUOTE=esalaka;36133230]The current directory should never be in LD_LIBRARY_PATH by default anyway, why would you even consider trying?[/QUOTE] Chill, I know almost nothing about Linux. [editline]30th May 2012[/editline] Is it so terrible to think it might be able to work when the libs are in the same place as the executable, regardless of some environment setting
[QUOTE=NovembrDobby;36133271]Chill, I know almost nothing about Linux. [editline]30th May 2012[/editline] Is it so terrible to think it might be able to work when the libs are in the same place as the executable, regardless of some environment setting[/QUOTE] Yeah it is actually, Linux doesn't need libraries included with their programs as they can be installed as a dependency. This also means that the versions of the libraries won't always be the same. This is why it's a good idea to create a build system using autotools or cmake that'll automatically build your program for the target system and link against whatever version of library their distro has. This unfortunately also means you'll have to release source code with it. Although if you don't want to give your code to paying customers, you can do something like the penumbra or overgrowth team. They have some weird installer called Nixstaller that manages to configure the application to the system and install it properly without exposing any code. [editline]adsdf[/editline] If you chat me up on steam or gmail chat (naelstrof @ gmail.com) I'll talk to you how I got the build system in my engine working. It even compiles to windows. It can be found on github here: [url]https://github.com/naelstrof/Astrostruct[/url]
These are my shaders for diffused lighting: [cpp] #version 120 uniform mat4 MVP; uniform mat4 Model; attribute vec4 Position; attribute vec2 UV; attribute vec3 Normals; varying vec2 uv; varying vec3 normals; void main(){ vec3 norm = (Model * Position * vec4(Normals, 1.0f) ).xyz; normals = normalize( norm ); uv = UV; gl_Position = MVP * Position; } [/cpp] and: [cpp] #version 120 varying vec2 uv; uniform sampler2D Texture; uniform bool DrawLines; varying vec3 normals; uniform vec4 AmbientLight; uniform vec4 DiffuseLight; void main(){ vec4 textureColor = texture2D( Texture, uv ).rgba; vec4 AmbientColor = vec4(AmbientLight.rgb, 1.0f) * AmbientLight.a; float DiffuseFactor = dot(normals, -1 * DiffuseLight.rgb); vec4 DiffuseColor = vec4(0, 0, 0, 0); if (DiffuseFactor > 0.0f) { DiffuseColor = vec4(AmbientLight.rgb, 1.0f) * DiffuseLight.a * DiffuseFactor; } vec4 color = textureColor * (AmbientColor + DiffuseColor); gl_FragColor = vec4(color.rgb, textureColor.a); } [/cpp] The normals for the blocks are calculated as: [cpp] if( !(v[0].HasNormals() && v[1].HasNormals() && v[2].HasNormals() ) ) { glm::vec3 U = (v2.Position - v1.Position); glm::vec3 V = (v3.Position - v1.Position); glm::vec3 norm = glm::cross(U, V); v[0].Normal = norm; v[1].Normal = norm; v[2].Normal = norm; }[/cpp] when I apply this lighting setting it seems to work fine: [code] chunk->SetAmbient(glm::vec4(0.8f, 0.6f, 0.5f, 0.5f) ); chunk->SetDiffuse(glm::vec4(0.0f, 0.0f, 0.6f, 0.9f) );[/code] producing: [img]http://i.imgur.com/IlKd8.png[/img] Yet when I use this: [cpp] chunk->SetAmbient(glm::vec4(0.8f, 0.6f, 0.5f, 0.5f) ); chunk->SetDiffuse(glm::vec4(0.6f, 0.0f, 0.0f, 0.9f) );[/cpp] Which I would have assumed gives only the right side lighting i get this: [IMG]http://i.imgur.com/8U0UF.png[/IMG] Is that normal?
[QUOTE=download;36128654]I'm having trouble finding information on Try/Catch in Java. Anyone think they could tell me how to use it to catch someone entering something that is not an integer?[/QUOTE] [url]http://docs.oracle.com/javase/tutorial/essential/exceptions/try.html[/url]
[QUOTE=download;36128654]I'm having trouble finding information on Try/Catch in Java. Anyone think they could tell me how to use it to catch someone entering something that is not an integer?[/QUOTE] It's quite simple really. Here's some example code; [code] int whatever; SomeInput input = new SomeInput(); // This could be anything, a JOptionDialogue, or whatever you use. try { whatever = Integer.parseInt(input.getValue()); // Again, this isn't accurate. } catch (NumberFormatException e) { // This exception will happen if something isn't an Integer. // Handle the exception. } [/code] There are exceptions for quite a few things. And all you need to do to test for Integer values it put a Integer.parseInt() call inside a try block. I assume the same can be said for most of the other base types too.
Quick Java question: When reading from a file, is it possible to make the FileReader ignore some parts of the data in the file? For example, assume my file contains the following text: [code]Records: 3 Max's Severed Head: 2 Lugermorph: 1 Officer's Ushanka: 5[/code] I want the program to read the numbers after the text and associate them to certain variables. Is there a way to use a loop and check for the colon mark within the file and set the value that follows it to an integer variable? If there is, how would I go about doing it?
[QUOTE=hexpunK;36137251]It's quite simple really. Here's some example code; [code] int whatever; SomeInput input = new SomeInput(); // This could be anything, a JOptionDialogue, or whatever you use. try { whatever = Integer.parseInt(input.getValue()); // Again, this isn't accurate. } catch (NumberFormatException e) { // This exception will happen if something isn't an Integer. // Handle the exception. } [/code] There are exceptions for quite a few things. And all you need to do to test for Integer values it put a Integer.parseInt() call inside a try block. I assume the same can be said for most of the other base types too.[/QUOTE] So, try something that only works on integers, if it breaks it goes to catch?
Im trying to draw lines along the normals to debug this lighting issue but my code only seems to draw the first vertexes line, can someone check if im sending in the right data to OGL? I have checked the lineList and this is filled correctly [cpp] #ifdef DEBUG GLuint linebuffer; std::vector<glm::vec3> lineList; lineList.clear(); for(int i = 0; i < IndexList.size(); i++) { for(int j = 0; j < 3; j++) { glm::vec3 Ps = PosList[ IndexList[i] + j ]; glm::vec3 Pe = PosList[ IndexList[i] + j ] + (NormList[ IndexList[i] + j ] ); lineList.push_back(Ps); lineList.push_back(Pe); } } SOGLF::Shader sh = SOGLF::Shader("./basic.vert" , "./basic.frag"); GLuint lMVPID = glGetUniformLocation(sh.GetShaderID(), "MVP"); GLuint lPositionID = glGetAttribLocation(sh.GetShaderID(), "Position"); glGenBuffers(1, &linebuffer); glBindBuffer(GL_ARRAY_BUFFER, linebuffer); glBufferData(GL_ARRAY_BUFFER, lineList.size() * sizeof(glm::vec3), &lineList[0], GL_STATIC_DRAW); sh.Bind(); glUniformMatrix4fv(lMVPID, 1, GL_FALSE, &MVP[0][0]); glEnableVertexAttribArray(lPositionID); glBindBuffer(GL_ARRAY_BUFFER, linebuffer); glVertexAttribPointer( lPositionID, // 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 ); glDrawArrays(GL_LINES, 0, 2); glDisableVertexAttribArray(lPositionID); SOGLF::Shader::Unbind(); glDeleteBuffers(1, &linebuffer); #endif[/cpp] [editline]31st May 2012[/editline] [QUOTE=Overv;36148037]Could you start over and explain what exactly you're trying to do? From what I gather: you position chunks using a translation and this somehow messes with your normals, thus causing your lighting to fail. It seems to me that you're not keeping your matrices apart correctly and you merged everything into one. Could you give an overview of your rendering process and shaders in pseudocode? Please post it in WDYNHW.[/QUOTE] So from the chunk I create N*N*N blocks by passing a position something like: [CODE]for X < width: for Y < Height: for X < depth: b = new Block(X,Y,Z);[/CODE] The block then gets created by using the position: [CODE]for i < 6: Side = new Side( position, front/back/left/right/top/bottom )[/CODE] This automatically creates the normals using this: [url]http://www.opengl.org/wiki/Calculating_a_Surface_Normal[/url] The blocks verticies and normals (and uv's) get added to one single vector (one for vertex, uv, normals) I then pass through all blocks and check that these exist and only add the index of vissible sides to the index list. I then construct the buffers and pass to OGL as normal. And the shaders you can see in previous posts, with regards to the * Position thing, when I use * Position I get correct lighting with a Z value on the diffuse direction but with X or Y values only the sides towards the center of the chunk are light up. When I dont times it by Position then all sides of the blocks have light regardless of the diffuse values
[QUOTE=download;36139986]So, try something that only works on integers, if it breaks it goes to catch?[/QUOTE] Sorta. You have the right idea. But it's a bit more limited than that. A common way to test for Integer values in Java is to use the parseInt() method provided in the Integer class, because it is told to throw a NumberFormatException (the one we put in the catch brackets). There are probably a few more methods that do the same. But for checking if something is safe as an int, parseInt() is a good bet. parseInt() should throw a NumberFormatException for Strings like "abc", "af3452", etc. As they cannot be parsed as ints due to letters. But a String like "1234" is perfectly safe. Floats, doubles, and other int types should all be fine too.
parseInt is a good way of doing that yeah
[QUOTE=Richy19;36148021]And the shaders you can see in previous posts, with regards to the * Position thing, when I use * Position I get correct lighting with a Z value on the diffuse direction but with X or Y values only the sides towards the center of the chunk are light up. When I dont times it by Position then all sides of the blocks have light regardless of the diffuse values[/QUOTE] Why are you inverting the normals for the dot product calculation? It's like your entire shader code went through a human obfuscation program.
Sorry, you need to Log In to post a reply to this thread.