• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=Richy19;35872991]If in OpenGL(2.1) I have a scene like the left, therefore the user views the right. Does the cube actually get rendered?[/QUOTE] The vertex transformations and whatnot will always occur. The GPU will try to create fragments for every polygon, but the actual shading may or may not occur depending on the results of depth testing. This is why a lot of games do early-z passes or render front-to-back; it saves on shading overhead in forward renderers. Effectively, you may save on some fragment shading, but you still have to actually process the primitives. This is why we have visibility testing and occlusion queries in games.
Hello again folks, I require assistance once again in Visual basic 2010. I wouldn't ask this if I hadn't committed hours trying to solve it myself. But I need to get this nifty little simulation give somewhat logical numbers instead of astronomical coordinates and infinite decimals. Here's what I have trouble with in my nuclear strike simulator. There's a certain percentage of people from the total population of the city in certain range, and certain percent of those people in those ranges die. [code]Public Class Form1 Dim Oulu As Integer = 150000 ' Population of this city Dim Oulun_pinta_ala As Double = (1000 * 1410.17) ^ 2 'Area of whole city turned from square kilometers(1410.17) to meters Dim Oulun_asukastiheys As Integer = Oulu / Oulun_pinta_ala 'population density Dim Asukkaita_1140m_säteellä As Double = (1140 * 1140) * 3.14 / Oulun_pinta_ala * Oulu 'population in this range in meters Dim Asukkaita_3050m_säteellä As Double = (3050 * 3050) * 3.14 / Oulun_pinta_ala * Oulu 'population in this range in meters Dim Asukkaita_6200m_säteellä As Double = (6200 * 6200) * 3.14 / Oulun_pinta_ala * Oulu 'population in this range in meters[/code] [code] Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click If lblAsukasmaara.Text = "0" Then MsgBox("Valitse Kaupunki") End If If lblAsukasmaara.Text = Oulu Then kuollut1 = (100 - 88) / 100.0 * Asukkaita_1140m_säteellä 'death toll in these ranges kuollut2 = (100 - 33) / 100.0 * Asukkaita_3050m_säteellä kuollut3 = (100 - 11) / 100.0 * Asukkaita_6200m_säteellä yht = kuollut1 + kuollut2 + kuollut3 tulo1 = kuollut1 tulo2 = kuollut2 tulo3 = kuollut3 [/code] But I get results like this (note that "kuollut", "kuolleita" etc means "dead") [code]Kuolleita 1140 metrin säteellä: 0,0369376203597919 Kuolleita 3050 metrin säteellä: 1,47622462665414 Kuolleita 6200 metrin säteellä: 8,10310283100606 Kuolleita yhteensä: 9,61626507801999[/code] please forgive my stupidity :c
Hey everyone. I am in c++ programming in college and I could use a little help with a final project. This is my project; [code] Your programming assignment is to develop a program to find out the winner of the gymnastics competition. The winner is the gymnast with the highest score. Each gymnast will receive a score from seven (7) judges. The highest and lowest score will be thrown out. The remaining five scores will be averaged to determine the gymnast final score. The output will list each gymnast with their final score followed by the overall winner. Your input will come from a file with the name - OLYMPICS.TXT and have the data listed as follows OLGA KORBUT 8.8 7.8 3.4 8.9 10.0 6.5 9.9 MARY LOU RETTON 5.6 5.5 6.5 7.5 4.8 2.1 4.5 NADIA COMANECI 9.9 8.9 9.4 9.3 9.6 8.8 9.2 The number of Gymnasts in the file will vary. The results will be written to a file called - FINAL.TXT and have the format of Gymnast Score OLGA KORBUT 8.38 MARY LOU RETTON 5.38 NADIA COMANECI 9.28 The winner is NADIA COMANECI[/code] I am having trouble with this concept. All we have learned this year is basic stuff. This one has to do with loops and files. I am not sure how to go about this. I have tried doing some code for the past few days and cant figure this out correctly. Any tips or help will be greatly appreciated. What I know I should do is create a loop that inputs all the values and creates a high low type deal. I am not sure how to go about that correctly.
[code] case WM_MOUSEMOVE: mousePT.x = (int)LOWORD(lParam); mousePT.y = (int)HIWORD(lParam); dx = mousePT.x - gOldPos.x; dy = mousePT.y - gOldPos.y; Camera().onPitch(dx); Camera().onYaw(dy); gOldPos = mousePT; break; [/code] Ran into an issue with using the Win API for input, for some reason this does not work at all in moving the camera. (Camera Code) [code] void Camera::onPitch(float angle) { D3DXMATRIX R; D3DXMatrixRotationAxis(&R, &gRight, angle); D3DXVec3TransformNormal(&gUp, &gUp, &R); D3DXVec3TransformNormal(&gLook, &gLook, &R); } void Camera::onYaw(float angle) { D3DXMATRIX R; D3DXMatrixRotationY(&R, angle); D3DXVec3TransformNormal(&gRight, &gRight, &R); D3DXVec3TransformNormal(&gUp, &gUp, &R); D3DXVec3TransformNormal(&gLook, &gLook, &R); } void Camera::onRoll(float angle) { D3DXMATRIX R; D3DXMatrixRotationZ(&R, angle); D3DXVec3TransformNormal(&gUp, &gUp, &R); D3DXVec3TransformNormal(&gRight, &gRight, &R); } [/code]
[QUOTE=Commando123;35900096]Hey everyone. I am in c++ programming in college and I could use a little help with a final project. This is my project; [code] Your programming assignment is to develop a program to find out the winner of the gymnastics competition. The winner is the gymnast with the highest score. Each gymnast will receive a score from seven (7) judges. The highest and lowest score will be thrown out. The remaining five scores will be averaged to determine the gymnast final score. The output will list each gymnast with their final score followed by the overall winner. Your input will come from a file with the name - OLYMPICS.TXT and have the data listed as follows OLGA KORBUT 8.8 7.8 3.4 8.9 10.0 6.5 9.9 MARY LOU RETTON 5.6 5.5 6.5 7.5 4.8 2.1 4.5 NADIA COMANECI 9.9 8.9 9.4 9.3 9.6 8.8 9.2 The number of Gymnasts in the file will vary. The results will be written to a file called - FINAL.TXT and have the format of Gymnast Score OLGA KORBUT 8.38 MARY LOU RETTON 5.38 NADIA COMANECI 9.28 The winner is NADIA COMANECI[/code] I am having trouble with this concept. All we have learned this year is basic stuff. This one has to do with loops and files. I am not sure how to go about this. I have tried doing some code for the past few days and cant figure this out correctly. Any tips or help will be greatly appreciated. What I know I should do is create a loop that inputs all the values and creates a high low type deal. I am not sure how to go about that correctly.[/QUOTE] Use sscanf to parse the data for each line, then loop through the numbers to find the highest and lowest score to discard them. Then get the remaining five scores and average them. It'd look something like this: [code]std::ifstream File; File.open("path/to/file.txt"); while (File.good()) { char FirstName[32]; char LastName[32]; float Scores[7]; char Buffer[256]; File.getline(Buffer,256); sscanf(Buffer,"%s %s %f %f %f %f %f %f %f",FirstName,LastName,&Scores[0],&Scores[1],&Scores[2],&Scores[3],&Scores[4],&Scores[5],&Scores[6]); float Min =10; float Max = 0; for (unsigned int i=0;i<7;i++) { if (Scores[i]>Max) { Max = Scores[i]; } if (Scores[i]<Min) { Min = Scores[i]; } } float Average = 0; for (unsigned int i=0;i<7;i++) { if (Scores[i] != Min && Scores[i] != Max) { Average += Scores[i]; } } Average/=5; std::cout << FirstName << " " << LastName << " average score is " << Average << "\n"; }[/code] Sorry for the lack of formatting, chrome won't let me tab.
Would you be able to do it with like simple looping and basic file i/o? We have not done arrays. I am completely lost. I am very new to this stuff and we only covered basic input, basic control structures, and functions.. lol Basically where I am thrown off in the file is how to get the names first then loop through the 7 numbers, knock off high and low, then move on to the next one infinitely. I'm not sure how to go about that. I understand your code but we are not to that level yet and I need to write it in more simpler terms.. The professor would not like me using arrays when he has not even hit them. I made myself a basic High Low code but I dont know where to go from here. [code] #include <fstream> using namespace std; int main() { ifstream scores; ofstream winners; int number, high, low; scores.open("scores.txt"); winners.open("winners.txt"); scores >> number; low = number; high = number; while (number >= 0) { if (number > high) high = number; if (number < low) low = number; scores >> number; } winners << "the highest number in the list is " << high << endl << endl; winners << "the lowest number in the list is " << low << endl << endl; scores.close(); winners.close(); return(0); } [/code] I just made the input file a string of numbers.
In XNA, is 'matrix.Backward' the same as '-matrix.Forward'?
[QUOTE=Funley;35916119]In XNA, is 'matrix.Backward' the same as '-matrix.Forward'?[/QUOTE] I do not think it is. The order of matrix calculations does matter.
I made a game using code::blocks and sfml, but how do I build the release version without the "terminal" window and including variables, imgs, sounds, etc.. in the .exe file? thanks in advance
[QUOTE=Commando123;35909208]Would you be able to do it with like simple looping and basic file i/o?[/QUOTE] It seems really pointless to avoid useful tools and abilities of the language. Your teacher shouldn't punish you for going above and beyond
Stringstream can help you when you have 3 names. Or one. So instead of parsing a first and last name you can just cin into a string. Also, write a function to split up a string with space delimiters, and return a string vector full of it. Then use a stringstream to test if the vector index is a string or a double ( istringstream >> int won't do anything if the stringstream can't be converted to int) and then do stuff accordingly.
I keep getting this: [quote]|36|undefined reference to `SOGLF::Keyboard::IsKeyDown(SOGLF::Keyboard::Keys)'|[/quote] I have it declared as: [cpp] namespace SOGLF { class Keyboard { enum Keys{...}; static inline bool IsKeyDown(SOGLF::Keyboard::Keys key); }; } [/cpp] and defined in a cpp file as: [cpp] bool SOGLF::Keyboard::IsKeyDown(SOGLF::Keyboard::Keys key) { bool result = false; switch (key) { .... } return result; } [/cpp]
So I needed a position to screen method which is pretty much gluProject, so I wrote that: [cpp]bool Renderer::Project(const Vector3f& position, const Vector2i& windowSize, Vector2f& result) const { Vector4f in(position.x, position.y, position.z, 1.0f); in = m_projection * (m_modelView * in); if (in.w == 0.0f) { return false; } in.x /= in.w; in.y /= in.w; in.z /= in.w; in.x = in.x * 0.5f + 0.5f; in.y = in.y * 0.5f + 0.5f; in.z = in.z * 0.5f + 0.5f; result.x = in.x * windowSize.x; result.y = windowSize.y - (in.y * windowSize.y); return true; } [/cpp] The only problem is that the screen position is still on the screen when the position I'm projecting is behind the near clipping plane. So in that situation, I either need a way to make it return a position thats outside the screen (so I can clamp sprites to the edge to see what direction something is in) or find out if the point is behind the near clipping plane. [editline]13th May 2012[/editline] It seems I can just return out if the w component is less than 0.001, seems to work and that's what the source engine does, so whatever, it's good enough for me.
[QUOTE=Richy19;35925323]I keep getting this: I have it declared as: [cpp] namespace SOGLF { class Keyboard { enum Keys{...}; static inline bool IsKeyDown(SOGLF::Keyboard::Keys key); }; } [/cpp] and defined in a cpp file as: [cpp] bool SOGLF::Keyboard::IsKeyDown(SOGLF::Keyboard::Keys key) { bool result = false; switch (key) { .... } return result; } [/cpp][/QUOTE] You should define inline functions within the header file. Also, make sure you actually want/need an inline function. [url]http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.7[/url] [quote]It's usually imperative that the function's definition (the part between the {...}) be placed in a header file. If you put the inline function's definition into a .cpp file, and if it is called from some other .cpp file, you'll get an "unresolved external" error from the linker.[/quote]
Time to ask for help at Facepunch too I guess. I'm trying to add physics to my 3D game engine however the mesh is ending up horribly mis-aligned. [IMG]http://dl.dropbox.com/u/11197643/offsetmesh2.png[/IMG] [IMG]http://dl.dropbox.com/u/11197643/offsetmesh.png[/IMG] I'm using Jitter since it seems quite nice and it doesn't want to do everything for you. I'm trying to build a compound shape of convex hulls, one for each mesh in the model. Currently however the different hulls are being transformed incorrectly, resulting in a misaligned mesh. [url]http://pastebin.com/PNkWVfsz[/url] is my current physics entity class. Any help is much appreciated.
[QUOTE=elih595;35880934][url]http://pastebin.com/PVbfMQG8[/url] I'm trying make the player collide with the wall. The wall is a 31x31 cube but I can only make the player collide on the left face of the cube. I can't figure out how to add more sides without them overriding each other.[/QUOTE] You could save the movement direction of the player and move it back with the reversed speed. Else you do something like this inside the block collision test: [code] if((playerX+26 >= wallX)and(playerX <= wallX+26)and(playerY+26 >= wallY)and(playerY <= wallY+26))then if(playerX+13 <= wallX+13) then //Move player to left else then //Move player to right end end [/code] I could be wrong with those values, I basically are trying to determinate if the player is to the right/left of the block. [QUOTE=Mete;35916573]I made a game using code::blocks and sfml, but how do I build the release version without the "terminal" window and including variables, imgs, sounds, etc.. in the .exe file? thanks in advance[/QUOTE] Did some searching and found this, pretty much what you ask about the terminal: [url]http://en.sfml-dev.org/forums/index.php?topic=595.0[/url] Baking images and sounds in the exe is NOT recommended since it will make the exe file giant. Instead, encrypt your resources or make them to binary or something if you want to protect them. However I found this: [url]http://en.sfml-dev.org/forums/index.php?topic=7089.msg46783#msg46783[/url]
(In C#) How do I create a menu in which I can choose between different options? [IMG]http://f2.braxupload.se/v1r8oz.alternativ.png[/IMG] ^like that
[QUOTE=JohanGS;35942298](In C#) How do I create a menu in which I can choose between different options? [IMG]http://f2.braxupload.se/v1r8oz.alternativ.png[/IMG] ^like that[/QUOTE] You might look at the RadioCheck property [url]http://msdn.microsoft.com/en-us/library/system.windows.forms.menuitem.radiocheck(v=vs.71).aspx[/url]
Ugh... Been trying to get this for awhile now. This should be easy, but for some reason I guess I just suck with vectors. [img]http://i.imgur.com/wM8RC.png[/img] I need to check to see if a cord(x, y) is within the diamond in the square. in this function [code] private bool IsoLogic(Rectangle dimension, Vector2 sp) { Vector2 start = new Vector2(dimension.X, dimension.Y); if (sp.X > start.X && sp.Y > start.Y) { if ((sp.Y >= sp.X / 2) && (sp.X < start.X + 32 && sp.Y < start.Y + 16)) //check upper left { return true; } if ((sp.X <= sp.Y / 2) && (sp.X < start.X + 64 && sp.Y < start.Y + 16)) //check upper right { return true; } if ((sp.X <= sp.Y) && (sp.X < start.X + 32 && sp.Y < start.Y + 32)) //check bottom left { return true; } if ((sp.X >= sp.Y) && (sp.X < start.X + 64 && sp.Y < start.Y + 32)) //check bottom right { return true; } } return false; } [/code] This is the closest I've gotten, but it still doesn't work correctly. Vector2 start gets the upper left corner of the square. Vector2 sp is the vector of the mouse which I am checking to see if it is inside of the diamond or not.
[QUOTE=ben1066;35940258]Time to ask for help at Facepunch too I guess. I'm trying to add physics to my 3D game engine however the mesh is ending up horribly mis-aligned. [IMG]http://dl.dropbox.com/u/11197643/offsetmesh2.png[/IMG] [IMG]http://dl.dropbox.com/u/11197643/offsetmesh.png[/IMG] I'm using Jitter since it seems quite nice and it doesn't want to do everything for you. I'm trying to build a compound shape of convex hulls, one for each mesh in the model. Currently however the different hulls are being transformed incorrectly, resulting in a misaligned mesh. [url]http://pastebin.com/PNkWVfsz[/url] is my current physics entity class. Any help is much appreciated.[/QUOTE] How do you define the origin of your models? IIRC Jitter adjusts the origin of rigid bodies to their center of mass.
[QUOTE=Mr_Razzums;35944556]Ugh... Been trying to get this for awhile now. This should be easy, but for some reason I guess I just suck with vectors. [img]http://i.imgur.com/wM8RC.png[/img] I need to check to see if a cord(x, y) is within the diamond in the square. in this function [code] private bool IsoLogic(Rectangle dimension, Vector2 sp) { Vector2 start = new Vector2(dimension.X, dimension.Y); if (sp.X > start.X && sp.Y > start.Y) { if ((sp.Y >= sp.X / 2) && (sp.X < start.X + 32 && sp.Y < start.Y + 16)) //check upper left { return true; } if ((sp.X <= sp.Y / 2) && (sp.X < start.X + 64 && sp.Y < start.Y + 16)) //check upper right { return true; } if ((sp.X <= sp.Y) && (sp.X < start.X + 32 && sp.Y < start.Y + 32)) //check bottom left { return true; } if ((sp.X >= sp.Y) && (sp.X < start.X + 64 && sp.Y < start.Y + 32)) //check bottom right { return true; } } return false; } [/code] This is the closest I've gotten, but it still doesn't work correctly. Vector2 start gets the upper left corner of the square. Vector2 sp is the vector of the mouse which I am checking to see if it is inside of the diamond or not.[/QUOTE] [cpp]ratio = 64.0 / 32.0; // ratio of x/y maxdist = 32.0; dx = (center.x - pos.x); dy = (center.y - pos.y) * ratio; d = abs(dx) + abs(dy); return (d <= maxdist);[/cpp] The metric to get "circles" that look like diamonds is [img]http://latex.codecogs.com/gif.latex?\sum%20_{k=1}%20^n%20|a_k%20-%20b_k|[/img], and it defines taxicab geometry. Yours is just a squished diamond, so one axis gets scaled before summation. [editline]14th May 2012[/editline] Don't worry if that doesn't make any sense
I want to make a board game using Java. (to learn it better) I am a beginner and i was wondering what imports to use and if anyone could point me in the right direction with where to start. Also tutorials that i should definitely read for this. I have an image with the board itself. Things what i want to be able to do: - i want to be able to specify the amount of players and then have that amount of pawns. - a dice - drag and drop the pawns
@Silverboarder The real Drag & Drop interface works easy with components, but as you just wish to DND with some own images within the scope of your own program (and just within one JComponent) you can skip DND interface this and just use the mouse listener for this. For the easy way (just mouse listener) you just need minimal knowledge of swing. You only want an initial frame asking how many players (possible board+pawn images) and reuse this frame to add the a panel as canvas for the drawing. More interesting is the Graphis2D interface, you will use it for drawing your images. But in most simple case you will only use the drawImage. Just make a subclass of JPanel and overwrite the paint. From here you can use the Graphics2D interface. Add the mouse listener (to either frame or panel) and you're almost done ;) It becomes more complicated if you actually want to add game-logic etc. Marco
Can anyone see anything in my shader class that would cause a segfault? [cpp] #ifndef sSHADER_HPP_INCLUDE #define sSHADER_HPP_INCLUDE #pragma once #include <string> #include <map> #include <vector> #include <GL/glew.h> class Shader { protected: GLuint VertexShaderID; GLuint FragmentShaderID; std::string FragmentShaderCode; std::string VertexShaderCode; GLuint shaderID; void LoadVertexShader(std::string &fileName); void LoadFragmentShader(std::string &fileName); void CompileVertexShader(GLint &Result, int &InfoLogLength); void CompileFragmentShader(GLint &Result, int &InfoLogLength); std::map< std::string, GLuint > UniformVariableIDList; std::map< std::string, GLuint > AttributeVariableIDList; public: /// /// \brief Empty constructor /// Shader(); /// /// \brief Construct shader with given files /// \param Vertex shader filename /// \param Fragment shader filename /// Shader(const std::string &vertFileName, const std::string &fragFileName); /// /// \brief Deconstructor /// ~Shader(); /// /// \brief Retreive the shaders ID /// GLuint GetShaderID(); /// /// \brief Bind the shader for use /// void Bind(); /// /// \brief Deactivate all shaders /// static void Unbind(); /// /// \brief Get the ID of a given attribute /// \param Attribute name /// GLuint GetAttribute(const std::string attName); /// /// \brief Get the ID of a given uniform /// \param Uniform name /// GLuint GetUniform(const std::string uniName); }; #endif //SHADER_HPP_INCLUDE [/cpp] [cpp] #include <iostream> #include <fstream> #include <GL/glew.h> #include <glm/glm.hpp> #include "Shader.hpp" Shader::Shader() {} Shader::Shader(const std::string &vertFileName, const std::string &fragFileName) { AttributeVariableIDList.clear(); UniformVariableIDList.clear(); /// Create the shaders VertexShaderID = glCreateShader(GL_VERTEX_SHADER); FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); /// Read the Vertex Shader code from the file std::string VertexShaderCode; std::ifstream VertexShaderStream(vertFileName.c_str(), std::ios::in); if(VertexShaderStream.is_open()) { std::string Line = ""; while(getline(VertexShaderStream, Line)) VertexShaderCode += "\n" + Line; VertexShaderStream.close(); } /// Read the Fragment Shader code from the file std::string FragmentShaderCode; std::ifstream FragmentShaderStream(fragFileName.c_str(), std::ios::in); if(FragmentShaderStream.is_open()) { std::string Line = ""; while(getline(FragmentShaderStream, Line)) FragmentShaderCode += "\n" + Line; FragmentShaderStream.close(); } GLint Result = GL_FALSE; int InfoLogLength; /// Compile Vertex Shader printf("Compiling shader : %s ", vertFileName.c_str()); char const * VertexSourcePointer = VertexShaderCode.c_str(); glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL); glCompileShader(VertexShaderID); /// Check Vertex Shader glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result); glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); std::vector<char> VertexShaderErrorMessage(InfoLogLength); glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]); fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]); /// Compile Fragment Shader printf("Compiling shader : %s ", fragFileName.c_str()); char const * FragmentSourcePointer = FragmentShaderCode.c_str(); glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL); glCompileShader(FragmentShaderID); /// Check Fragment Shader glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result); glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); std::vector<char> FragmentShaderErrorMessage(InfoLogLength); glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]); fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]); /// Link the program fprintf(stdout, "Linking program "); GLuint ProgramID = glCreateProgram(); glAttachShader(ProgramID, VertexShaderID); glAttachShader(ProgramID, FragmentShaderID); glLinkProgram(ProgramID); /// Check the program glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result); glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength); std::vector<char> ProgramErrorMessage( glm::max(InfoLogLength, int(1)) ); glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]); fprintf(stdout, "%s\n", &ProgramErrorMessage[0]); Shader::shaderID = ProgramID; } Shader::~Shader() { glDeleteProgram(shaderID); glDeleteShader(VertexShaderID); glDeleteShader(FragmentShaderID); } void Shader::LoadVertexShader(std::string &fileName) { try { std::ifstream VertexShaderStream(fileName.c_str(), std::ios::in); if(VertexShaderStream.is_open()) { std::string Line = ""; while(getline(VertexShaderStream, Line)) VertexShaderCode += "\n" + Line; VertexShaderStream.close(); } } catch(int e) { std::cout << "Failed to open Vertex shader, using basic shader." << std::endl << e << std::endl; //VertexShaderCode = } } void Shader::LoadFragmentShader(std::string &fileName) { try { std::ifstream FragmentShaderStream(fileName.c_str(), std::ios::in); if(FragmentShaderStream.is_open()) { std::string Line = ""; while(getline(FragmentShaderStream, Line)) FragmentShaderCode += "\n" + Line; FragmentShaderStream.close(); } } catch(int e) { std::cout << "Failed to open Frag shader, using basic shader." << std::endl << e << std::endl; FragmentShaderCode = "void main(){ gl_FragColor = vec4(1,1,1,1); }"; } } void Shader::CompileVertexShader(GLint &Result, int &InfoLogLength) { /// Compile Vertex Shader std::cout << "Compiling Vertex Shader" << std::endl; char const * VertexSourcePointer = VertexShaderCode.c_str(); glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL); glCompileShader(VertexShaderID); /// Check Vertex Shader glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result); glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); std::vector<char> VertexShaderErrorMessage(InfoLogLength); glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]); std::cout << &VertexShaderErrorMessage[0] << std::endl; } void Shader::CompileFragmentShader(GLint &Result, int &InfoLogLength) { /// Compile Fragment Shader std::cout << "Compiling Fragment Shader" << std::endl; char const * FragmentSourcePointer = FragmentShaderCode.c_str(); glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL); glCompileShader(FragmentShaderID); /// Check Fragment Shader glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result); glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); std::vector<char> FragmentShaderErrorMessage(InfoLogLength); glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]); std::cout << &FragmentShaderErrorMessage[0] << std::endl; } GLuint Shader::GetShaderID() { return shaderID; } void Shader::Bind() { glUseProgram(shaderID); } void Shader::Unbind() { glUseProgram(0); } GLuint Shader::GetAttribute(std::string attName) { std::map<std::string, GLuint>::iterator it = AttributeVariableIDList.find(attName); if (it != AttributeVariableIDList.end()) { return it->second; } GLuint attribute = glGetAttribLocation(shaderID, attName.c_str()); AttributeVariableIDList[attName] = attribute; } GLuint Shader::GetUniform(std::string uniName) { std::map<std::string, GLuint>::iterator it = UniformVariableIDList.find(uniName); if (it != UniformVariableIDList.end()) { return it->second; } GLuint uniform = glGetAttribLocation(shaderID, uniName.c_str()); UniformVariableIDList[uniName] = uniform; } [/cpp]
[QUOTE=ThePuska;35949550][cpp]ratio = 64.0 / 32.0; // ratio of x/y maxdist = 32.0; dx = (center.x - pos.x); dy = (center.y - pos.y) * ratio; d = abs(dx) + abs(dy); return (d <= maxdist);[/cpp] The metric to get "circles" that look like diamonds is [img]http://latex.codecogs.com/gif.latex?\sum%20_{k=1}%20^n%20|a_k%20-%20b_k|[/img], and it defines taxicab geometry. Yours is just a squished diamond, so one axis gets scaled before summation. [editline]14th May 2012[/editline] Don't worry if that doesn't make any sense[/QUOTE] Heh well its alright I got it now... Took me way too long to make this algorithm... [code] float min; float high; if (sp.X > start.X && sp.Y > start.Y && (sp.X < start.X + 64 && sp.Y < start.Y + 32)) { if (nc.X < 32) { min = 16 - (nc.X / 2); high = (nc.X / 2) + 16; if (nc.Y > min && nc.Y < high) return true; } else if (nc.X >= 32) { min = (nc.X / 2) - 16; high = 32 - min; if (nc.Y > min && nc.Y < high) return true; } } return false; [/code] Math is my weakness... and it really shows in my programming :/
[QUOTE=Richy19;35951387]Can anyone see anything in my shader class that would cause a segfault? [code][/QUOTE] use a debugger set a breakpoint and find out yourself seriously that should be in the OP - "set a breakpoint and step through your code"
[QUOTE=Protocol7;35952604]use a debugger set a breakpoint and find out yourself seriously that should be in the OP - "set a breakpoint and step through your code"[/QUOTE] This is what my debbuger gives me: [code] valgrind ./FPSd ==2350== Memcheck, a memory error detector ==2350== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==2350== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info ==2350== Command: ./FPSd ==2350== ==2350== Jump to the invalid address stated on the next line ==2350== at 0x0: ??? ==2350== by 0x804D4CF: Block::Block() (Block.cpp:4) ==2350== by 0x804A39E: Block3d::Block3d() (Chunk.hpp:6) ==2350== by 0x804A3FC: Chunk::Chunk() (Chunk.hpp:18) ==2350== by 0x804A14A: Program::Program() (Program.cpp:7) ==2350== by 0x804D310: main (Main.cpp:6) ==2350== Address 0x0 is not stack'd, malloc'd or (recently) free'd ==2350== ==2350== ==2350== Process terminating with default action of signal 11 (SIGSEGV) ==2350== Bad permissions for mapped region at address 0x0 ==2350== at 0x0: ??? ==2350== by 0x804D4CF: Block::Block() (Block.cpp:4) ==2350== by 0x804A39E: Block3d::Block3d() (Chunk.hpp:6) ==2350== by 0x804A3FC: Chunk::Chunk() (Chunk.hpp:18) ==2350== by 0x804A14A: Program::Program() (Program.cpp:7) ==2350== by 0x804D310: main (Main.cpp:6) ==2350== ==2350== HEAP SUMMARY: ==2350== in use at exit: 9,785,834 bytes in 338 blocks ==2350== total heap usage: 583 allocs, 245 frees, 9,862,264 bytes allocated ==2350== ==2350== LEAK SUMMARY: ==2350== definitely lost: 0 bytes in 0 blocks ==2350== indirectly lost: 0 bytes in 0 blocks ==2350== possibly lost: 4,118 bytes in 112 blocks ==2350== still reachable: 9,781,716 bytes in 226 blocks ==2350== suppressed: 0 bytes in 0 blocks ==2350== Rerun with --leak-check=full to see details of leaked memory ==2350== ==2350== For counts of detected and suppressed errors, rerun with: -v ==2350== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 88 from 11) Segmentation fault[/code] (Block.cpp:4) being the shader constructor
then put a breakpoint on the constructor and step through it until you find the offending line
In C#, is it possible to copy entire folders, to another folder, filled with different files that can be images, text, more folders, and files that have unknown file extensions.
[QUOTE=Funley;35955005]In C#, is it possible to copy entire folders, to another folder, filled with different files that can be images, text, more folders, and files that have unknown file extensions.[/QUOTE] yes
Sorry, you need to Log In to post a reply to this thread.