• What Do You Need Help With? V6
    7,544 replies, posted
I'm starting to think that my problem originates from GLFW or some other third party lib.
[QUOTE=KatNotDinner;44903672]What do you mean?[/QUOTE] Your triangle's vertex draw order might be off. Instead of drawing it in this order: bottom left, middle, bottom right, try bottom right, middle, bottom left. I've had problems with this sort of thing before.
Do I have to change the positions of the vertecies in the array or do I have to do something else?
[QUOTE=KatNotDinner;44903919]Do I have to change the positions of the vertecies in the array or do I have to do something else?[/QUOTE] Try changing the position of the vertices in the array. Also, I was looking at your shaders, they seem.. off. I might be wrong but I'm pretty sure the vec4 color has to go through the vertex shader first. From what it seems, nothing is being passed to the input in the frag shader. Here is a working vertex and fragment shader that I have used many times. Vertex: [CODE] layout (location = 0) in vec3 inPoint; layout (location = 1) in vec4 inColor; out vec4 outColor; void main() { outColor = inColor; gl_Position = vec4(inPoint, 1.0); } [/CODE] Fragment: [CODE] in vec4 outColor; void main(){ gl_FragColor = outColor; } [/CODE] I believe that these shaders were written for OpenGL 3.0+, so I don't know about OpenGL 4.0+. You may have to do some translations, for instance, I think gl_FragColor is deprecated. But the general consensus is that you send the point and the color into the vertex shader, the vertex shader uses the point and ignores the color and sends it to the fragment shader, and the fragment shader outputs that color.
God bless you. This explains why when I used core 330 I couldn't use layout() in the fragment shader. I didn't even know colors have to go through vertex shader. It does make sense though, since vertex shader is ran before fragment.
[QUOTE=KatNotDinner;44903993]God bless you. This explains why when I used core 330 I couldn't use layout() in the fragment shader. I didn't even know colors have to go through vertex shader. It does make sense though, since vertex shader is ran before fragment.[/QUOTE] I'm glad I could help :)
Updated link with code, incase anyone else encounters the same problem.
I'm trying to add string elements from a file into a vector. [code]#include <iostream> #include <string> #include <fstream> #include <vector> using namespace std; int main() { string line; vector<string> numbers; ifstream grid ("test.txt"); if (grid.is_open()) { while (getline(grid, line)) { for (int i = 0; i < line.size(); i++) { if (!isspace(line[i])) numbers.push_back(line[i]); } cout << endl; } grid.close(); } else cout << "unable to open file.\n"; for (int i = 0; i < numbers.size(); i++) cout << numbers[i]; cout << endl; return 0; }[/code] However, I cannot push_back lines[i] into the vector. Why?
[QUOTE=NixNax123;44905490]I'm trying to add string elements from a file into a vector. [code]...[/code] However, I cannot push_back lines[i] into the vector. Why?[/QUOTE] line[i] returns a char, not a string. In C++03 you need to construct a temporary string out of it[cpp]numbers.push_back(string(1, line[i]));[/cpp] and if you can use C++11 you can directly emplace it[cpp]numbers.emplace_back(1, line[i]);[/cpp] Edit: Depending on what you want to actually do, you might want to do what WTF Nuke says (make it a vector<char>/string) or insert the whole line (without [i]) into the vector.
Line is a string, when you access it with a [] you get a char. Maybe make it a vector of chars instead?
Okay, simple question here. The code works when I have it like this [code] function love.draw() x = 0 --y = 0 for value = 1, #map, 1 do if map[value] == 1 then love.graphics.draw(grassTile, x, 0) x = x + 64 end end end [/code] but doesn't work when I add on the elseif [code]function love.draw() x = 0 --y = 0 for value = 1, #map, 1 do if map[value] == 1 then love.graphics.draw(grassTile, x, 0) x = x + 64 end elseif map[value] == 0 then x = x + 64 end end end[/code] I get an error that says I need to put an end for the For loop, except I do have one. On further inspection, according to Notepad++, the second to last 'End' ends the function. Except this shouldn't be how it's happening, because I have to close 4 things. I have to close the function, the for loop, the if statement, and the elseif statement. I'll show a screenshot. [IMG]http://i.imgur.com/sbp1vhI.png[/IMG] See how the last end doesn't end the function like it should? Well it does if I remove the ElseIf. [IMG]http://i.imgur.com/Vxcrm6K.png[/IMG] Why is this happening? It completely breaks everything. Edit: I FIXED IT LIKE 2 SECOND AFTER MAKING THIS POST. Okay so if you make an If statement, and you want an elseif, you don't put an end to the if statement and the elseif statement. You just put an end to both of them. I feel like an idiot, but meh I resign to being an idiot.
It's because you need the elseif after the if, not after the end of the if. so.. [code] if x then something elseif y then more end --NOT if x then something end --BAD elseif y then more end [/code] [editline]26th May 2014[/editline] Yeah you got it, well done.
[QUOTE=Dienes;44906221]and if you can use C++11 you can directly emplace it[cpp]numbers.emplace_back(1, line[i]);[/cpp] [/QUOTE] That worked perfectly! Thanks!
Working with lua, LÖVE and Mogamett, how do I change the PhysicsBody (the bounding box) of an object? [code] -- Ducking if mg.input:down('duck') then -- Set physics body to half height end -- Not ducking? if not mg.input:down('duck') then -- Return to default end [/code] I'm thinking that I have to use the attributes (?) listed on this page but I'm not sure how to change them. Through some method? Can you just do something like [code] self.PhysicsBody.h = 14[/code] other than the fact that it doesn't work? [editline]26th May 2014[/editline] sorry, on this page: [url]http://mogamett.com/documentation/physicsbody/[/url]
I'm having extreme difficulty getting colors to work correctly in openGL. My test render code is as follows: [B]EDIT:[/B] removed my rendering code, it was big and I don't think it's the issue [img]http://i.imgur.com/5FMrA1b.png[/img] When my 4 textures are these: [img]http://i.imgur.com/2K9NsZF.png[/img] [editline]27th May 2014[/editline] It colors everything the color of the last texture I loaded [img]http://i.imgur.com/QM18WhM.png[/img] Maybe its a problem with my loader? [code]int loadTexture(char *file) { // Load the image SDL_Surface *tex = IMG_Load(file); GLuint texture; cout << "Loading image: " << string(file) << "\n"; if (tex) { glGenTextures(1, &texture); // Generating 1 texture glBindTexture(GL_TEXTURE_2D, texture); // Bind the texture glTexImage2D(GL_TEXTURE_2D, 0, 3, tex->w, tex->h, 0, GL_RGB, GL_UNSIGNED_BYTE, tex->pixels); // Map texture glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Set minifying parameter to linear glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Set magnifying parameter to linear SDL_FreeSurface(tex); // Free the surface from memory cout << " > Image loaded: " << string(file) << "\n\n"; return texture; // return the texture index } else { cout << " > Failed to load image: " << IMG_GetError() << "\n\n"; SDL_FreeSurface(tex); // Free the surface from memory return -1; // return -1 in case the image failed to load } }[/code] [editline]27th May 2014[/editline] I load my textures like this: [code]textTest = loadTexture("assets/test_texture_64.png"); textTest2 = loadTexture("assets/test_texture2_64.png"); textTest3 = loadTexture("assets/heightMap_clouds_64.png"); textTest4 = loadTexture("assets/test_texture4_64.png");[/code] it only loads the last texture loaded.
You gotta bind those textures whenever you want to use them.
I am [code]//Front glBindTexture(GL_TEXTURE_2D, textTest); glNormal3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 2.0f); glVertex3f(-1.5f, -1.0f, 1.5f); // a glNormal3f(1.0f, 0.0f, 1.0f); glTexCoord2f(2.0f, 2.0f); glVertex3f(1.5f, -1.0f, 1.5f); // b glNormal3f(1.0f, 0.0f, 1.0f); glTexCoord2f(2.0f, 0.0f); glVertex3f(1.5f, 1.0f, 1.5f); // c glNormal3f(-1.0f, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.5f, 1.0f, 1.5f); // d //Right glBindTexture(GL_TEXTURE_2D, textTest2); glNormal3f(1.0f, 0.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(1.5f, -1.0f, -1.5f); glNormal3f(1.0f, 0.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(1.5f, 1.0f, -1.5f); glNormal3f(1.0f, 0.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(1.5f, 1.0f, 1.5f); glNormal3f(1.0f, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(1.5f, -1.0f, 1.5f);[/code] Still uses the last texture loaded.
[QUOTE=Pat.Lithium;44920343]I am [code]//Front glBindTexture(GL_TEXTURE_2D, textTest); glNormal3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 2.0f); glVertex3f(-1.5f, -1.0f, 1.5f); // a glNormal3f(1.0f, 0.0f, 1.0f); glTexCoord2f(2.0f, 2.0f); glVertex3f(1.5f, -1.0f, 1.5f); // b glNormal3f(1.0f, 0.0f, 1.0f); glTexCoord2f(2.0f, 0.0f); glVertex3f(1.5f, 1.0f, 1.5f); // c glNormal3f(-1.0f, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.5f, 1.0f, 1.5f); // d //Right glBindTexture(GL_TEXTURE_2D, textTest2); glNormal3f(1.0f, 0.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(1.5f, -1.0f, -1.5f); glNormal3f(1.0f, 0.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(1.5f, 1.0f, -1.5f); glNormal3f(1.0f, 0.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(1.5f, 1.0f, 1.5f); glNormal3f(1.0f, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(1.5f, -1.0f, 1.5f);[/code] Still uses the last texture loaded.[/QUOTE] Unbind your texture before drawing the background: [code]glBindTexture(GL_TEXTURE_2D, 0);[/code]
Thats not the issue, each side of the box has a different texture but they all show up as the last loaded texture. [t]http://i.imgur.com/WxOIgjM.png[/t]
Oh, last loaded, not last bound. Sorry, I misunderstood the problem.
Figured it out, I was binding the texture after glBegin, instead of before. now my game looks beautiful [t]http://i.imgur.com/JnohaYV.png[/t] Anyone know where I can download a nice low poly model of a plane (like a ww2 plane) royalty free?
Did any of them fail to load? [editline]27th May 2014[/editline] Oh, you ninja'd me with your fix. Congratulations. :)
[QUOTE=Pat.Lithium;44920343]I am [code]//Front glBindTexture(GL_TEXTURE_2D, textTest); glNormal3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 2.0f); glVertex3f(-1.5f, -1.0f, 1.5f); // a glNormal3f(1.0f, 0.0f, 1.0f); glTexCoord2f(2.0f, 2.0f); glVertex3f(1.5f, -1.0f, 1.5f); // b glNormal3f(1.0f, 0.0f, 1.0f); glTexCoord2f(2.0f, 0.0f); glVertex3f(1.5f, 1.0f, 1.5f); // c glNormal3f(-1.0f, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.5f, 1.0f, 1.5f); // d //Right glBindTexture(GL_TEXTURE_2D, textTest2); glNormal3f(1.0f, 0.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(1.5f, -1.0f, -1.5f); glNormal3f(1.0f, 0.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(1.5f, 1.0f, -1.5f); glNormal3f(1.0f, 0.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(1.5f, 1.0f, 1.5f); glNormal3f(1.0f, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(1.5f, -1.0f, 1.5f);[/code] Still uses the last texture loaded.[/QUOTE] Old fixed-function pipeline !!! This is madness !
java question So for my CS101 class I need to make a game in Greenfoot. I'm trying to use an array to manage the map so tat when I go to the left of the screen, the array will change the map to the map that is one item to the left in the array, so for example in the array [code] { {new a1(), new a2()}, {new b1(), new b2()} } [/code] going to the left of the screen on map b2 would take you to b1. I've got that working, but the problem is that when the player tries to go back to the previous map, the last player object to use that screen is stuck at the wall, infinitely switching from one map to another. I fixed that by simply deleting the player object after teleporting, but what I want to do now is make it so the player teleports to the left side of the next screen when using the right teleporter, the bottom of the next screen when using to top teleporter, etc. and I can't seem to figure it out. Right now the player isn't actually being teleported, but is instead being killed and then re-created on the next screen, so I need it to get the last known location of the last player in the previous screen, tell the next screen which teleporter it used, and then use this information to put the new player in the appropriate place on the next screen. Any ideas?
I'm playing around with F# (hi tamschi), and in my travels I've noticed a few people preferring this kind of syntax: [code]let validMove = newPosition |> validPosition map[/code] Instead of this: [code]let validMove = validPosition map newPosition[/code] Is there any difference to this, or is it down to convention and/or personal preference?
Not really, no. It does help if you have multiple such calls though, since they will be in order of operation this way. Actually, there's another benefit: You don't need brackets if the argument is calculated from a function, since function calls have higher precedence than |>.
I see, that makes sense. Things have been going fairly well so far, though I'm a bit confused about this. I have this at the top of my file: [code]type RayHit = { mapPos : Vector2f; side : int }[/code] And a recursive raycast function that returns a RayHit value when it hits a solid block in the map: [code]// Steps a ray forwards until a wall is hit. let rec stepRay (deltaDist:Vector2f) (sideDist:Vector2f) (mapPos:Vector2f) (step:Vector2f) side = if map.[int mapPos.X, int mapPos.Y] = 0 then // If we're still in empty space... if sideDist.X < sideDist.Y then // If the next intersection will be an X-axis side... let nextSideDist = sideDist + new Vector2f(deltaDist.X, 0.0f) let nextMapPos = mapPos + new Vector2f(step.X, 0.0f) stepRay deltaDist nextSideDist nextMapPos step 0 // Step again, since we haven't hit anything yet. else let nextSideDist = sideDist + new Vector2f(0.0f, deltaDist.Y) // If the next intersection will be a Y-axis side... let nextMapPos = mapPos + new Vector2f(0.0f, step.Y) stepRay deltaDist nextSideDist nextMapPos step 1 // Step again, since we haven't hit anything yet. else // We hit something { RayHit.mapPos = mapPos; RayHit.side = side } // Return the RayHit data.[/code] I would expect this function's return type to be 'RayHit', but according to my IDE it actually seems to be 'int -> RayHit' which, if I'm not mistaken, means a function that takes an integer and returns a RayHit. Where is this behaviour coming from? Also, feel free to point out any ugly practises I've picked up and things like that; the earlier I learn the good practises, the better! [editline]27th May 2014[/editline] If it helps, I'm implementing a raycaster based on [url=http://lodev.org/cgtutor/raycasting.html]this[/url], attempting to adapt it to a more functional style of doing things as I go.
This is more of a math question than a programming question, but this is the best place I can think of asking it. I generated a random vector with the X and Y values on a unit circle and the Z value being 1. I want to model bullet spread, so using an angle I multiply the X and Y by tan(angle). I then normalize this vector. Now comes the tricky part, which I'm not sure how to do. I want to rotate this vector in the same way that I would have rotated another vector, that is to go from (0,0,1) to whatever the other vector is. How would I do this? Would this work? resultant = glm::rotate(glm::quat(normRef), randomVec); No, it doesn't. However, glm::rotation() does the job.
[QUOTE=BackwardSpy;44926195][...] I would expect this function's return type to be 'RayHit', but according to my IDE it actually seems to be 'int -> RayHit' which, if I'm not mistaken, means a function that takes an integer and returns a RayHit. Where is this behaviour coming from? [...][/QUOTE] That's [URL="http://fsharpforfunandprofit.com/posts/partial-application/"]partial application[/URL], if you only give it four parameters you get a function that takes the fifth as first one and returns the result from all parameters. Note that the type of your function is [code]Vector2f -> Vector2f -> Vector2f -> Vector2f -> int -> RayHit[/code], so essentially you give it one parameter each time and get a new function that takes the next one and takes a function again. (This is not what it compiles to, but it behaves exactly like this.) You can remove the parameter types here, the compiler is smart enough to figure that out from the function body. It also works by being used from other, distinct, call sites.
Ah, I forgot to pass in a value for the 'side' parameter, you're right. Thanks a lot for your help! I started adding those because for some reason it wasn't figuring them out properly earlier, though that may have been the result of an error somewhere. I'll start removing them again and see how far I get. Thanks again. :) [editline]28th May 2014[/editline] Hm, the type inference works for everything that isn't SFML .NET's Vector2f type. Is this something I'm doing wrong, or is it due to the nature of referenced binaries or whatever?
Sorry, you need to Log In to post a reply to this thread.