[QUOTE=Jookia;31167362]I forgot, you're not suppose to use the right tool for the job, even if doing so sacrifices compiler optimizations and code readability.[/QUOTE]
So you're saying that if you want to do a project with a language that isn't optimized to make applications specifically like the one you're making, you should learn a new language? That's silly.
[QUOTE=Mr. Smartass;31167633]So you're saying that if you want to do a project with a language that isn't optimized to make applications specifically like the one you're making, you should learn a new language? That's silly.[/QUOTE]
I'm saying to use for loops instead of while loops that do the same thing as for loops.
[QUOTE=ruarai;31168618]Can someone tell me whats wrong with my code i posted before? I am really desperate..[/QUOTE]
Are you sure the progressbar value isn't 0 to 1?
Any guys here with a bit of experience with building Box2D in C++?
I followed these instructions after getting the latest build off SVN:
[quote]For Microsoft Visual Studio:
- Run the cmake-gui
- Set the source directory to the path of Box2D on your PC (the folder that contains this file).
- Set the build directory to be the path of Box2D/Build on your PC.
- Press the Configure button and select your version of Visual Studio.
- You may have to press the Configure button again.
- Press the Generate button.
- Open Box2D/Build/Box2D.sln.
- Set the Testbed or HelloWorld as your startup project.
- Press F5 or Ctrl-F5 to run.[/quote]
However there is no Box2D.sln... but there is a Project.sln. There's no TestBed or HelloWorld project either?
Error I'm getting in Visual Studio when I try build something after opening Project.sln:
[img]http://dl.dropbox.com/u/12453703/box2d_2.GIF[/img]
Posted this just incase I fucked up the directory location:
[img]http://dl.dropbox.com/u/12453703/box2d_1.GIF[/img]
Any ideas? I've tried the build process for both VS2008 and VS2010.
[QUOTE=agnl;31160719]totally missed that, thanks; it works now.
[editline]16th July 2011[/editline]
So I got the entire program to work except for the quit sequence, it gives me a runtime error when I enter quit. What is wrong with my program?
[cpp]
#include <cassert>
#include <fstream>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
string astring;
ifstream infile;
string filename;
string quit;
char prevchar;
char currchar;
int count;
while (filename != "quit")
{
cout << "Please type the name of the input file (Type 'quit' to exit): ";
cin >> filename;
infile.open(filename.c_str());
assert(infile);
infile >> astring;
count = 0;
infile.get(currchar);
infile.get(prevchar);
while (infile)
{
if (currchar == ' ')
count++;
prevchar = currchar;
infile.get(currchar);
}
cout << count << " spaces found." << endl;
infile.close(); //THIS HAS TO BE AT THE END OF THE WHILE QUIT LOOP!!
infile.clear(); //AS DOES THIS, DO NOT FORGET!!!
}
system("PAUSE");
return EXIT_SUCCESS;
}
[/cpp][/QUOTE]
When you enter 'quit' it will try to open a file named 'quit' and if there is none, the assertion will fail, thus an error will get raised.
[QUOTE=genkaz92;31162563]That was definitely quite a snap, thank you.
I actually have another question to this thread. Does anyone here use pseudocode? or a method of working out the general logical structure/pattern of their code before actually typing it out?[/QUOTE]
For more or less trivial things you can keep in your mind, I just make out the algorithm like that and then write it down in C++.
For more complicated algorithms I work it out on paper, but not in any sort of programming code. I just kinda doodle around, trying to think of a way to solve the problem and once I have an idea write it in C++ and test it. Perhaps google the problem to find efficient solutions.
It's just a matter of experience. When you're used to C++, you'll find it easy to just write down heaps of code intuitively.
My pseudo-code is often quite like C++ btw. For the stuff we have to write on paper on university I also mix in some Python to make it shorter though :P
[QUOTE=ruarai;31163560][code]
players.Text = info[1];
maxplayers.Text = info[2];
name.Text = info[3];
gamemode.Text = info[4];
p = Convert.ToInt32(info[1]);
mp = Convert.ToInt32(info[2]);
ap = p / mp;
progressBar1.Value = ap * 100;
[/code]
The info array is filled up like
"37", - Players
"120", - Max Players
"NameOfServer",
"Gamemode"
Why wont this make the progress bar show the percentage of the people on the server to the max allowed on the server? All it does is display 0 on the progress bar.[/QUOTE]
When you divide an integer by an integer, the result is an integer as well.
[QUOTE=ruarai;31163560][code]
players.Text = info[1];
maxplayers.Text = info[2];
name.Text = info[3];
gamemode.Text = info[4];
p = Convert.ToInt32(info[1]);
mp = Convert.ToInt32(info[2]);
ap = p / mp;
progressBar1.Value = ap * 100;
[/code]
The info array is filled up like
"37", - Players
"120", - Max Players
"NameOfServer",
"Gamemode"
Why wont this make the progress bar show the percentage of the people on the server to the max allowed on the server? All it does is display 0 on the progress bar.[/QUOTE]
you must typecast p or mp to float when dividing otherwise you are doing integer division (meaning no decimals).
:ninja:
[QUOTE=Chrispy_645;31169381]Any guys here with a bit of experience with building Box2D in C++?
I followed these instructions after getting the latest build off SVN:
However there is no Box2D.sln... but there is a Project.sln. There's no TestBed or HelloWorld project either?
Error I'm getting in Visual Studio when I try build something after opening Project.sln:
[img]http://dl.dropbox.com/u/12453703/box2d_2.GIF[/img]
Posted this just incase I fucked up the directory location:
[img]http://dl.dropbox.com/u/12453703/box2d_1.GIF[/img]
Any ideas? I've tried the build process for both VS2008 and VS2010.[/QUOTE]
How does your configuration look? Building shared libraries? Static? Where's your install/output paths?
Here's one I compiled for my SFML 2.0 project, you can try using it: [url]http://solidfiles.com/d/5ea48/[/url] (it's static libraries, not shared)
hey guys!
I was wondering if you guys could check and see if what I am doing is safe and tell me about anything I could improve in one core function I have in my program
[code]void GetPicture()
{
int ammount = 0;// Ammount of times .jpg is in the file
char *helper = buffer; // buffer is the website;
char *Begin = NULL; // the start of the .jpg file ,"../img/logo_ndp.jpg", where "." will be the start
char BeginF;
char * Buffer; // This will hold the whole .jpg string, ../img/logo_ndp.jpg
while( ( helper=strstr(helper,".jpg") )!= NULL ) // find first occurence of .jpg
{
ammount++;
Begin = helper;
BeginF = *Begin; // place the value of it to our char
while( BeginF !='"' )// check to see if we aren't at the start
{
Begin --;
BeginF = *Begin;
}
Buffer = new char[];// is this safe??
memcpy(Buffer,Begin+1, helper-Begin +3 ); // copy the string from the start to the end ( adresses )
cout << Buffer << endl;
helper+=strlen(".jpg");
}
cout << ammount << endl;
delete( Buffer );
}[/code]
it basically searches buffer for any occurrence of .jpg then it grabs the whole address of it
this is a WiP , I'm going to make it universal for all file formats later.
Are you working in C or C++? Because if you're using C++, there's lots of stuff you could use from the STL.
A function that begins with 'Get' and returns void.
Jookia, it's probably taking values by reference or as a pointer. Mind showing the declaration?
[QUOTE=Robbis_1;31170581]How does your configuration look? Building shared libraries? Static? Where's your install/output paths?
Here's one I compiled for my SFML 2.0 project, you can try using it: [url]http://solidfiles.com/d/5ea48/[/url] (it's static libraries, not shared)[/QUOTE]
Could you elaborate on that a bit? Sorry about that... I'm just feeling really stuck at the moment.
Anyways I downloaded your .rar file and I saw that you had the lib files and include folder... which is what I wanted to try and build, so I could include it in my VC++ directories and therefore use it with SFML. :smile:
I'm using c++.
[editline]17th July 2011[/editline]
[QUOTE=Robbis_1;31170812]Jookia, it's probably taking values by reference or as a pointer. Mind showing the declaration?[/QUOTE]
It's a WiP but eventually it will send the picture address to a global array of chars.
oh and yeah if you guys see anything I could use in automating what I am doing please do tell , I am still a noob in c++
Alright here's what happens:
[cpp]#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
// Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib")
#pragma comment (lib, "AdvApi32.lib")
int main(int argc, char *argv[])
{
struct addrinfo hints, *res, *p;
int status;
char ipstr[INET6_ADDRSTRLEN];
if (argc != 2) {
fprintf(stderr,"usage: showip hostname\n");
//return 1;
}
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6 to force version
hints.ai_socktype = SOCK_STREAM;
if ((status = getaddrinfo(argv[1], NULL, &hints, &res)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
//return 2;
}
printf("IP addresses for %s:\n\n", argv[1]);
for(p = res;p != NULL; p = p->ai_next) {
void *addr;
char *ipver;
// get the pointer to the address itself,
// different fields in IPv4 and IPv6:
if (p->ai_family == AF_INET) { // IPv4
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
addr = &(ipv4->sin_addr);
ipver = "IPv4";
} else { // IPv6
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
addr = &(ipv6->sin6_addr);
ipver = "IPv6";
}
// convert the IP to a string and print it:
inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
printf(" %s: %s\n", ipver, ipstr);
}
freeaddrinfo(res); // free the linked list
return 0;
}[/cpp]
What happens here is that if I include the LEAN_AND_MEAN macro it will compile without problems, but it will automatically close itself like it is returning a number in the main loop (which it is, but not instantaneous). If I comment out the LEAN_AND_MEAN macro this happens:
[img]http://i.imgur.com/Ws7nY.png[/img]
(Note the vertical scrollbar)
Why? What am I doing wrong?
[QUOTE=marcin1337;31170686]hey guys!
I was wondering if you guys could check and see if what I am doing is safe and tell me about anything I could improve in one core function I have in my program
[code]void GetPicture()
{
int ammount = 0;// Ammount of times .jpg is in the file
char *helper = buffer; // buffer is the website;
char *Begin = NULL; // the start of the .jpg file ,"../img/logo_ndp.jpg", where "." will be the start
char BeginF;
char * Buffer; // This will hold the whole .jpg string, ../img/logo_ndp.jpg
while( ( helper=strstr(helper,".jpg") )!= NULL ) // find first occurence of .jpg
{
ammount++;
Begin = helper;
BeginF = *Begin; // place the value of it to our char
while( BeginF !='"' )// check to see if we aren't at the start
{
Begin --;
BeginF = *Begin;
}
Buffer = new char[];// is this safe??
memcpy(Buffer,Begin+1, helper-Begin +3 ); // copy the string from the start to the end ( adresses )
cout << Buffer << endl;
helper+=strlen(".jpg");
}
cout << ammount << endl;
delete( Buffer );
}[/code]
it basically searches buffer for any occurrence of .jpg then it grabs the whole address of it
this is a WiP , I'm going to make it universal for all file formats later.[/QUOTE]
Several things are wrong with it.
[cpp]void GetPicture()
{
// |include " to exclude stuff like .jpg.rar
const static std::string extension = ".jpg\"";
const static std::string::size_type extensionLength = extension.size();
int amount = 0;// Amount of times .jpg is in the file
const std::string buffer(buffer); // buffer is the website;
std::string::size_type end = 0, begin;
while( ( end = buffer.find( extension, end ) ) != std::string::npos )
{
// |use the prefix incement whenever possible
++amount;
begin = buffer.rfind( '\"', end );
cout << buffer.substr(begin + 1, end - begin + 3) << endl;
end += extensionLength;
}
cout << amount << endl;
}[/cpp]
That should do.
[QUOTE=Chrispy_645;31170816]Could you elaborate on that a bit? Sorry about that... I'm just feeling really stuck at the moment.
Anyways I downloaded your .rar file and I saw that you had the lib files and include folder... which is what I wanted to try and build, so I could include it in my VC++ directories and therefore use it with SFML. :smile:[/QUOTE]
Well yeah, that's the output when I compiled it, I uploaded it to save you the trouble of doing it. But when you start CMake and open the folder, there's a list of things first time you press Configure. Did you change anything or did you just press configure and generate? Because I had to change some things before generating.
[QUOTE=marcin1337;31170818]I'm using c++.
[editline]17th July 2011[/editline]
It's a WiP but eventually it will send the picture address to a global array of chars.
oh and yeah if you guys see anything I could use in automating what I am doing please do tell , I am still a noob in c++[/QUOTE]
Well, use the std::string class if you feel unsafe using char arrays. It also has some nice functions that might help you out and you don't need to worry about memory management or string copy.
Oh, I misunderstood Jookia's question. I thought he had a problem with a function that looked like that, hehe.
[editline]17th July 2011[/editline]
Looks like ZeekyHBomb already did it for you...
[QUOTE=eXiv2;31170888]What happens here is that if I include the LEAN_AND_MEAN macro it will compile without problems, but it will automatically close itself like it is returning a number in the main loop (which it is, but not instantaneous).[/QUOTE]
Windows closes the terminal when your program finishes. You need to either add a pause (usually getchar()) or actually invoke the program from a command prompt.
And yes, judging from your program it is instantaneous. Looking up an IP and printing a line doesn't take any time at all.
When I excluded the LEAN_AND_MEAN macro again I got a error that WSAstartup wasn't called. I might need to do that..
[editline]17th July 2011[/editline]
[QUOTE=ROBO_DONUT;31170987]Windows closes the terminal when your program finishes. You need to either add a pause (usually getchar()) or actually invoke the program from a command prompt.
And yes, judging from your program it is instantaneous. Looking up an IP and printing a line doesn't take any time at all.[/QUOTE]
You are correct. Changing the return 1; to a while(1); pauses the program but renders me unable to write anything. There still seems to be a fundamental flaw with my program. I did call WSAstartup this time and it seems to function more properly than before now.
[editline]17th July 2011[/editline]
Automerge?
[QUOTE=ZeekyHBomb;31170931]Several things are wrong with it.
[cpp]void GetPicture()
{
// |include " to exclude stuff like .jpg.rar
const static std::string extension = ".jpg\"";
const static std::string::size_type extensionLength = extension.size();
int amount = 0;// Amount of times .jpg is in the file
const std::string buffer(buffer); // buffer is the website;
std::string::size_type end = 0, begin;
while( ( end = buffer.find( extension, end ) ) != std::string::npos )
{
// |use the prefix incement whenever possible
++amount;
begin = buffer.rfind( '\"', end );
cout << buffer.substr(begin + 1, end - begin + 3) << endl;
end += extensionLength;
}
cout << amount << endl;
}[/cpp]
That should do.[/QUOTE]
thanks :D!
never knew things like rfind and find existed
[QUOTE=Chris220;31159449]So, I have a whole bunch of blocks rendering with OpenGL. Now, this is all fine if my blocks are opaque, but if I add translucent ones (i.e. water), I get some rendering errors. At the moment I'm using OpenGL's blending, but it seems that isn't good enough for my purposes.
Here's the issue:
Viewing the water from one side is fine:
[img]http://i.imgur.com/ONVWx.jpg[/img]
But when I move over it a bit, and view it from another angle...
[img]http://i.imgur.com/rHj9s.png[/img]
I'm not sure what's causing this, does anyone have any ideas?
Edit: In case you wondered, black water and black grids on the sand is for debugging purposes, not my own terrible artistic talent :v:
Also the fact that the water is black, but renders dark blue on the "wrong" image, shows that the background (sky) is showing through.[/QUOTE]
Anyone? I got it to "work" by using "Screen door transparency" (i.e the texture is a checkerboard of pixels, using 100% and 0% alpha every other pixel.) I'm not sure why this works and it looks ugly as hell, so... any help would be greatly appreciated!
It's alive!!
[QUOTE=ZeekyHBomb;31169599]
For more or less trivial things you can keep in your mind, I just make out the algorithm like that and then write it down in C++.
For more complicated algorithms I work it out on paper, but not in any sort of programming code. I just kinda doodle around, trying to think of a way to solve the problem and once I have an idea write it in C++ and test it. Perhaps google the problem to find efficient solutions.
It's just a matter of experience. When you're used to C++, you'll find it easy to just write down heaps of code intuitively.[/QUOTE]
I most definitely meant the structures and algorithms of actual programs which solve organized tasks rather then trivial little code chunks which can often be comfortably visualized.
According to my C++ experience so far, it can indeed be rather easy to trip over your own logic or have something pop up out of nowhere when attempting to purely visualize the algorithm as opposed to working it out and giving it basic (or giving it a level of detail that you are comfortable with) shape and then writing the actual code, while possibly making little tweaks along the way.
In other words, I definitely need to practice on developing a more consistent habit of working through and shaping the algorithms as much as possible before actually coding them.
So far it was always possible for me to break down lager algorithms into smaller ones, which an be pieced together fairly easy.
I rarely think of big structures as a monolithic thing, but rather a composition of modules. I then try to write the modules as flexible as possible for various reasons and at a later point I can stick it together with the rest.
[QUOTE=Chris220;31171295]Anyone? I got it to "work" by using "Screen door transparency" (i.e the texture is a checkerboard of pixels, using 100% and 0% alpha every other pixel.) I'm not sure why this works and it looks ugly as hell, so... any help would be greatly appreciated![/QUOTE]
What blending parameters were you using?
Your images look like only certain faces of the water blocks are being drawn, which is strange because that shouldn't be related to blending. If you go back to the code that produced those images, and disable GL_BLEND but change nothing else, what does the result look like?
quick question, I have a HTTP Get request in my code
[code] sprintf( buffer , "GET /site/pages/lol.html \r\n" );
send( HTTPServer , buffer , strlen( buffer ) , 0 );
sprintf( buffer, "Host: www.ecollege.ie \r\n" );
send( HTTPServer, buffer, strlen( buffer ) , 0 );
sprintf( buffer, "Connection: close\r\n" );
send( HTTPServer, buffer, strlen( buffer ) , 0 );
recv( HTTPServer, buffer, sizeof( buffer ), 0 );
cout << buffer << endl;[/code]
it sends me the the index file and in that index file I have a function that finds all files, then I send GETs to get all the files.
[code] sprintf( buffer , "GET /site/css/print.css \r\n" );
send( HTTPServer , buffer , strlen( buffer ) , 0 );
sprintf( buffer, "Host: www.ecollege.ie \r\n" );
send( HTTPServer, buffer, strlen( buffer ) , 0 );
recv( HTTPServer, buffer, sizeof( buffer ), 0 );[/code] for instance a css file
I get the index but then I don't get any files I request for. do I need to close the socket and re init it after every GET or what?
[QUOTE=Wyzard;31172429]What blending parameters were you using?
Your images look like only certain faces of the water blocks are being drawn, which is strange because that shouldn't be related to blending. If you go back to the code that produced those images, and disable GL_BLEND but change nothing else, what does the result look like?[/QUOTE]
Well, I'm only drawing the top faces of the top blocks of the body of water, just gives the nicest effect.
Here's what it looks like with and without GL_BLEND enabled:
[img]http://i.imgur.com/HpO8f.png[/img]
[img]http://i.imgur.com/uuetD.png[/img]
[QUOTE=Chris220;31174261]Well, I'm only drawing the top faces of the top blocks of the body of water, just gives the nicest effect.[/QUOTE]
It looked like you may have actually been drawing one of the side faces instead.
[QUOTE=Chris220;31174261]Here's what it looks like with and without GL_BLEND enabled:[/QUOTE]
Any chance of getting a pair of images from the same viewpoint?
What are you using for glBlendFunc? (GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA are probably what you want.)
I'm not really familiar with Minecraft, but do water blocks actually work like blocks, where you can remove one from the middle of the ocean or plop one onto dry land? If not, and water should always be just a single flat surface, it'd be much simpler to draw that surface as a single big rectangle — maybe one per chunk, or one for the bounding rectangle of all chunks currently loaded. You can use polygon offset to avoid problems with Z-fighting between the water plane and top faces of blocks at sea level.
If you take 3 vertices whose positions are local to the camera, and if they represent a triangle, how do you go about turning that into a fragment that could be drawn correctly to the screen (assuming you scaled)? Can you just ignore depth completely and fill in a 2d array when you are inside the triangle?
It's not quite clear what you mean by "local to the camera", but the first step is to transform the vertices from world coordinates to what OpenGL calls "clip coordinates", which are basically a cube whose sides, top, and bottom represent the edges of the window, and whose front and back are the near and far clipping planes. In clip space, the vertex's X and Y coordinates directly represent a 2D position within the window, and the Z coordinate directly represents the depth value.
Then you do 2D [url=http://www.devmaster.net/articles/software-rendering/part3.php]polygon rasterization[/url] on the triangle's X and Y coordinates to produce a set of fragments, and for each fragment you interpolate all the other attributes (including Z, aka depth).
[QUOTE=Wyzard;31174919]It's not quite clear what you mean by "local to the camera", but the first step is to transform the vertices from world coordinates to what OpenGL calls "clip coordinates", which are basically a cube whose sides, top, and bottom represent the edges of the window, and whose front and back are the near and far clipping planes. In clip space, the vertex's X and Y coordinates directly represent a 2D position within the window, and the Z coordinate directly represents the depth value.
Then you do 2D [url=http://www.devmaster.net/articles/software-rendering/part3.php]polygon rasterization[/url] on the triangle's X and Y coordinates to produce a set of fragments, and for each fragment you interpolate all the other attributes (including Z, aka depth).[/QUOTE]
Thanks, i couldnt find any decent explanations around
Sorry, you need to Log In to post a reply to this thread.