• What do you need help with? V. 3.0
    4,884 replies, posted
I'm very eager to learn networking in C++ but the only good tutorial I have found so far, with actual complete source code, was written for UNIX. It would require too much to be changed in the source code for me that I just don't feel like it. Does anyone have a good, comprehensive C++ networking tutorial with actual complete source code for Windows?
networking on Windows is exactly the same sans the name of closesocket and the WS initialization
[QUOTE=esalaka;31157755]networking on Windows is exactly the same sans the name of closesocket and the WS initialization[/QUOTE] IIRC, Microsoft took the entire BSD networking stack?
Well I'm still running into problems that I can't really solve at the moment by myself nor through Google it seems. Now I realize that we have a help thread, right here.. which I am posting it. If you don't mind I'll post the source. It's not mine, but I just want to compile it in Visual Studio 2010. [editline]16th July 2011[/editline] [cpp]#include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <arpa/inet.h> 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]
I'm working in Java on a very very basic rock paper scissors game, because I feel like learning Java. I've gotten this far [code]import java.util.Scanner; public class RPSGame{ /** * Rock Paper Scissors Game */ public static void main(String[] args) { int choicenum = 0; System.out.println("This is Rock Paper Scissors!"); System.out.println("Enter your choice of Rock, Paper, or Scissors!"); Scanner scan = new Scanner(System.in); String choice = scan.next(); System.out.println(choice); switch(choice.toLowerCase()){ case "rock": choicenum = 0; break; case "paper": choicenum = 1; break; case "scissors": choicenum = 2; break; } } [/code] What if the user enters something else other than rock, paper, or scissors? How would I say "Please enter "Rock", "Paper", or "Scissors"" and how would I go back to the scanner and get it to receive input again? Also, I'm about at the education level of a complete retard when it comes to this, so speak in baby please :\
[QUOTE=eXiv2;31158363]Well I'm still running into problems that I can't really solve at the moment by myself nor through Google it seems. Now I realize that we have a help thread, right here.. which I am posting it. If you don't mind I'll post the source. It's not mine, but I just want to compile it in Visual Studio 2010[/QUOTE] You have to change the headers for Windows. Winsock is in winsock2.h, not sys/sockets.h. You also need to do some extra initialization. MSDN has a [url=http://msdn.microsoft.com/en-us/library/ms738545(v=VS.85).aspx]guide[/url] specificially for Winsock. [editline]16th July 2011[/editline] Alternatively, you could just write UNIX-y code and compile with Cygwin.
Damn this half finished beta SFML 2.0 version, I cheered to early, apparently. The font errors were gone but another mystery raised to the surface, so I'm afraid I will have to ask you guys for one (hopefully) last favour. It just fails to draw some basic text to the window, both while constructing and after the construction of the other stuff. It gives no errors, warnings, whatsoever. The parts of the code in question: [CODE]sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Window");[/CODE] [CODE] sf::Font font; if (!font.LoadFromFile("arial.ttf")) { return EXIT_FAILURE; } sf::Text text; text.SetString("direct in constructor"); text.SetFont(font); text.SetColor(sf::Color(0, 128, 128)); text.SetPosition(100.f, 100.f); text.SetCharacterSize(50); sf::Text constructor("After constructor", sf::Font::GetDefaultFont(), 30.f); constructor.SetColor(sf::Color(128, 128, 128)); constructor.SetPosition(250.f, 250.f);[/CODE] [CODE] App.Clear(sf::Color(0, 128, 128)) App.Draw(text); App.Draw(constructor); App.Display(); [/CODE] Sorry for interrupting the serious questions, once again, whish I could contribute one time instead of only asking.
@Chezburger: I'm not sure I understand your problem, what exactly isn't working?
[QUOTE=Chris220;31159047]@Chezburger: I'm not sure I understand your problem, what exactly isn't working?[/QUOTE] This, also post all of your code not just that bit. And please, for the love of got dont do this [code]if (!font.LoadFromFile("arial.ttf")) { return EXIT_FAILURE; }[/code] Have it print out an error or exit with 1 or something, so you know that is the problem
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.
Alright I got the code that I previously linked to compile, but it automatically closes when I start it. I would guess it is returning a number which causes it to close. A pause at the end doesn't work. Any help?
[QUOTE=Richy19;31159157]This, also post all of your code not just that bit. And please, for the love of got dont do this [code]if (!font.LoadFromFile("arial.ttf")) { return EXIT_FAILURE; }[/code] Have it print out an error or exit with 1 or something, so you know that is the problem[/QUOTE] Thanks for the tip, I just picked it up from the tutorial, only to become a (bad?) habit. I encounterd what I think, is the problem, when I was stripping out every piece of unneeded code to make the search for the error easier. [CODE] glEnable(GL_DEPTH_TEST); [/CODE] together with this [code]glTranslatef(0.f, 0.f, -500.f); [/code] this prevents sf::Text from rendering to my window, but the question remains. Why? the text I want on the window renders fine when I comment that single line. And the whole code: [code] #include <stdafx.h> #include <iostream> #include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include <SFML/OpenGL.hpp> int main() { sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Window"); const sf::Input& Input = App.GetInput(); App.UseVerticalSync(true); App.SetActive(); glClearDepth(1.f); glClearColor(0.f, 0.f, 0.f, 0.f); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); // Causing trouble no.1 glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90.f, 1.f, 1.f, 500.f); while (App.IsOpened()) { //----------------------------------------------------------------------------------------------------------------------------------// sf::Event Event; while (App.GetEvent(Event)) { if (Event.Type == sf::Event::Closed) App.Close(); if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)) App.Close(); if (Event.Type == sf::Event::Resized) glViewport(0, 0, Event.Size.Width, Event.Size.Height); } //-----------------------------------------------------------------------------------------------------------------------------------// sf::Clock Clock; float Time = Clock.GetElapsedTime(); Clock.Reset(); float FramerateDeux = 1.f / App.GetFrameTime(); std::cout << "FRAMERATE:" << " " << FramerateDeux << std::endl; sf::Font font; if (!font.LoadFromFile("arial.ttf")) { return EXIT_FAILURE; } sf::Text text; text.SetString("direct in constructor"); text.SetFont(font); text.SetColor(sf::Color(0, 128, 128)); text.SetPosition(100.f, 100.f); text.SetCharacterSize(50); sf::Text constructor("After constructor", sf::Font::GetDefaultFont(), 30.f); constructor.SetColor(sf::Color(128, 128, 128)); constructor.SetPosition(250.f, 250.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.f, 0.f, -500.f); // Causing trouble no.2 // glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f); // glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f); // glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f); // glBegin(GL_QUADS); // glVertex3f(-50.f, -50.f, -50.f); // glVertex3f(-50.f, 50.f, -50.f); // glVertex3f( 50.f, 50.f, -50.f); // glVertex3f( 50.f, -50.f, -50.f); // glVertex3f(-20.f, -20.f, 50.f); // glVertex3f(-20.f, 20.f, 50.f); // glVertex3f( 20.f, 20.f, 50.f); // glVertex3f( 20.f, -20.f, 50.f); // glVertex3f(-50.f, -50.f, -50.f); // glVertex3f(-50.f, 50.f, -50.f); // glVertex3f(-50.f, 50.f, 50.f); // glVertex3f(-50.f, -50.f, 50.f); // glVertex3f( 50.f, -50.f, -50.f); // glVertex3f( 50.f, 50.f, -50.f); // glVertex3f( 50.f, 50.f, 50.f); // glVertex3f( 50.f, -50.f, 50.f); // glVertex3f(-50.f, -50.f, 50.f); // glVertex3f(-50.f, -50.f, -50.f); // glVertex3f( 50.f, -50.f, -50.f); // glVertex3f( 50.f, -50.f, 50.f); // glVertex3f(-50.f, 50.f, 50.f); // glVertex3f(-50.f, 50.f, -50.f); // glVertex3f( 50.f, 50.f, -50.f); // glVertex3f( 50.f, 50.f, 50.f); // glVertex3f(-60.f, 40.f, 40.f); // glVertex3f(-60.f, 40.f, -40.f); // glVertex3f( 60.f, 40.f, -40.f); // glVertex3f( 60.f, 40.f, 40.f); // glEnd(); App.Draw(text); App.Draw(constructor); App.Display(); } return EXIT_SUCCESS; } [/code]
I'm working on some homework and here's the problem: "Write a program that prints out the number of words in a file of text. We will define a word to be any sequence of non-whitespace characters. So "hi&there...mom" would be considered a single word. Solve this problem by using a string variable into which you input each word as a string. Here are some hints for assignments 5.4 and 5.5. Your program should ask the user for the name of the file to count words in (see the subsection in Dale titled "Run-Time Input of File Names", Dale 5th edition pp. 157 - 158 or Dale 4th edition pp. 159 - 160). It should loop until the user types "quit" for the name of the file. Turn in your source code, followed by an output which has the user entering these 5 input files: file 1 | file 2 | file 3 | file 4 | file 5 Using notepad......I suggest that you copy/paste the text from each of these five web pages to create five separate text files. Save these files in the same folder in which you have your working copy of your source code." Now I'm working on the simple input loop, and I can input once, but when it comes around again for another loop it gives me an error. Here's what I have: [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; 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; while (infile) { infile >> astring; cout << astring; } string filename; } system("PAUSE"); return EXIT_SUCCESS; } [/cpp]
[QUOTE=Chezburger;31159651]Thanks for the tip, I just picked it up from the tutorial, only to become a (bad?) habit. I encounterd what I think, is the problem, when I was stripping out every piece of unneeded code to make the search for the error easier. [/QUOTE] Its not necesairly a bad habbit, but imagne you had hundreds of things loading, how would you know which has crashed your program? Also you seem to be creating the fonts in the while loop, it would be much better to create them once before the while and just draw them inside the loop. As for your actual problem I dont know as im not really experienced with openGL so dont know what everything means
Just before the end of the loop, close the file.
Damn, not even realizing the sloppy mess I am creating. Well, I think I need to learn alot about openGL to see what's actually happening. Not like I was intending on using it all the time. Thanks for your input all!
[QUOTE=ROBO_DONUT;31158200]IIRC, Microsoft took the entire BSD networking stack?[/QUOTE] Probably the only occasion of Microsoft thinking doing things like others is a good idea
Anyone?
[QUOTE=eXiv2;31159612]Alright I got the code that I previously linked to compile, but it automatically closes when I start it. I would guess it is returning a number which causes it to close. A pause at the end doesn't work. Any help?[/QUOTE] Quick bump. Hope to get some help on this :v:
[QUOTE=agnl;31160410]Anyone?[/QUOTE] [QUOTE=ZeekyHBomb;31159916]Just before the end of the loop, close the file.[/QUOTE] That was intended for you. [editline]17th July 2011[/editline] [QUOTE=eXiv2;31159612]Alright I got the code that I previously linked to compile, but it automatically closes when I start it. I would guess it is returning a number which causes it to close. A pause at the end doesn't work. Any help?[/QUOTE] Try to debug.
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]
So far I appeared to have learned the C++ structure up to a pretty usable level, are there any recommendations or libraries that I could experiment with? I am ultimately interested in starting with something that I could create actual projects with, regardless of area of focus. I would also appreciate if someone could tell me a few words about the boost libraries, considering the fact of them being very popular. Or perhaps it is instead recommended to study Windows/general OS architecture, or CPU architecture, any recommendation is welcome.
[QUOTE=genkaz92;31161526]So far I appeared to have learned the C++ structure up to a pretty usable level, are there any recommendations or libraries that I could experiment with? I am ultimately interested in starting with something that I could create actual projects with, regardless of area of focus. I would also appreciate if someone could tell me a few words about the boost libraries, considering the fact of them being very popular. Or perhaps it is instead recommended to study Windows/general OS architecture, or CPU architecture, any recommendation is welcome.[/QUOTE] I read this post and snapped my fingers and pointed at the screen. [b]you should try [url=www.sfml-dev.org]SFML[/url][/b]
[QUOTE=AtomiCasd;31162181]I read this post and snapped my fingers and pointed at the screen. [B]you should try [URL="http://www.sfml-dev.org"]SFML[/URL][/B][/QUOTE] 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?
Hey, I'm reading 3D Math Primer for Graphics and Game Development right now and it is explaining everything greatly. However, when it got to the dot product, I got the Algebra part easy, (Add up the products of the corresponding components) however it then showed me a "Geometric Interpretation" with a picture like this: [IMG]http://i.imgur.com/N8h56.png[/IMG] Then, with no showing of how it got it whatsoever, it told me that the dot product of any 2 vectors is also the product of their magnitudes and the cosine of the angle in between them. (a*b=|a||b|cos(Theta)) I confirmed for myself that this works and I have used it to solve for the angle in between vectors but I don't know how they got it. If someone can walk me through it, I'm sure my understanding will be better on this.
[QUOTE=RoflKawpter;31158467]I'm working in Java on a very very basic rock paper scissors game, because I feel like learning Java. I've gotten this far [code]import java.util.Scanner; public class RPSGame{ /** * Rock Paper Scissors Game */ public static void main(String[] args) { int choicenum = 0; System.out.println("This is Rock Paper Scissors!"); System.out.println("Enter your choice of Rock, Paper, or Scissors!"); Scanner scan = new Scanner(System.in); String choice = scan.next(); //while(!choice.equals("rock") || !choice.equals("paper") || !choice.equals("scissors") ) { // choice = scan.next(); //} //I think this should work. System.out.println(choice); switch(choice.toLowerCase()){ case "rock": choicenum = 0; break; case "paper": choicenum = 1; break; case "scissors": choicenum = 2; break; } } [/code] What if the user enters something else other than rock, paper, or scissors? How would I say "Please enter "Rock", "Paper", or "Scissors"" and how would I go back to the scanner and get it to receive input again? Also, I'm about at the education level of a complete retard when it comes to this, so speak in baby please :\[/QUOTE]
I'm trying to start out a minecraft clone in XNA. I can get a quad showing, but it spreads my 16x16 texture out and smooths it... is there a way to prevent this? [img]http://dl.dropbox.com/u/8745051/ZScreen/2011-07/Cubes-2011-07-16_21.25.31.png[/img] [b]Edited:[/b] Figured it out.. needed to add SamplerState.PointClamp. Google is my friend.
[QUOTE=Sartek;31151035]I am trying to render the area for a game I am making using sfml 2 but when I run the program in windows 7 says it has crashed and I just see a white screen.[/QUOTE] Please stop. Learn a higher up language first before you tackle C++. Please. I beg you. Go learn Python. Or Lua. Or Ruby. Or anything that includes for loops. Then after a year, download Visual C++ Express and use that to compile your code.
[QUOTE=Jookia;31164390]Please stop. Learn a higher up language first before you tackle C++. Please. I beg you. Go learn Python. Or Lua. Or Ruby. Or anything that includes for loops. Then after a year, download Visual C++ Express and use that to compile your code.[/QUOTE] Its the coders choice to use while instead of for. For all we know, he could prefer it.
[QUOTE=Map in a box;31167319]Its the coders choice to use while instead of for. For all we know, he could prefer it.[/QUOTE] I forgot, you're not suppose to use the right tool for the job, even if doing so sacrifices compiler optimizations and code readability.
Sorry, you need to Log In to post a reply to this thread.