It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have to make a multiplayer game and give the users(on different) an option to change their screen resolution in order to sustain their hardware requirements.Similar to counterstrike.
How can I implement this in c ? how can I give the users sitting on different computers an option to change their screen resolution ?
There is no standard method in the C language or standard library, and this is entirely dependent on the graphics library you're writing the program in.
If you want a really simple way to do this, you can use xrandr and system():
#include <stdlib.h>
system("xrandr > resolutions.tmp"); // direct output to 'resolutions.tmp'
// retrieve possible resolutions from 'resolutions.tmp'
system("xrandr -s resolution_id"); // select a certain screen resolution
Edit: as you've mentioned you're using OpenGL on Ubuntu, you can follow some of the steps in the following article to change the resolution using library calls:
http://www.opengl.org/wiki/Programming_OpenGL_in_Linux:_Changing_the_Screen_Resolution
http://www.opengl.org/wiki/Programming_OpenGL_in_Linux:_Changing_the_Screen_Resolution worked for me. At the bottom you have command to compile, use it but add -std=c99. Keywords for google (no offense, I would appreciate them): opengl screen resolution
You will definitely use a library which handles the os-specific details for you. This library would be responsible for finding out which combinations fo screen resolution, colour depth and various buffers are available, and then you can choose one, or give the user the option to choose one.
For example, GLFW does this by way of its glfwGetVideoModes function.
The underlying code to do this is both platform-specific, and ugly. You want to spend some time writing your game not messing with it.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want to write a function in which when you tap "esc" the the window should close, the thing is that the function should be written in c.
I'am new to the c programming any help pls.
Well, for Windows:
GetActiveWindow or GetFocus to retrieve the window that is focused on.
GetASyncKeyState to capture the escape button.
SendMessage to close the respective window.
If you want something fancier than GetASyncKeyState(which is not reliable and expensive to the processor in an infinite loop) you can do something relatively difficult at first sight: global keyboard hooks in c
void myfunc(){
char ch;
do{
//do what you want here
ch=getchar();
}while(ch!='27'); //27 is the ascii code for esc
}
There is no standard way to react immediately to input in C - the ESC key is no different from the letter 'A' or 'x' in this respect - the input is not given to the program until the user hits Enter. Sometimes, a further complication is that ESC is used for special purposes, for example a Windows command-line application uses ESC for "erase whatever I've typed so far", which makes it impossible to read even with "ESC + Enter".
So, you need to use system specific functions that can read "raw" data from the keyboard, rather than the usual "cooked" data that you get using the standard I/O functions (e.g. getchar()).
There are OS-independent options, such as ncurses that supply this for console applications.
In windows, you may be able to use getch() after including conio.h, but this is a non-standard library, and it only works in a console application.
In a windowed environment it's a case of responding to a keyboard event, and "if key == ESCAPE close_window" - exactly how you do that depends on the windowing system and framework used.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I read that a running C program can be referred to as an "instance".
Is this really correct? The word instance is usually used for OOP.
And C also has "objects" hasn't it, but it's not the same as in OOP.
An "object" in C is just something in memory like a union with some value could be called an object can't it?
An "object" in C is just something in memory, but that's also true of all computer languages.
An object in real life is a thing that physically exists. Being in memory is the closest something in a program can come to physical existence, so we apply the same term.
An instance in real life is a specific example of a generic concept. The term has similar generality in computers. When you tell the computer to run a program, it generates an instance of that program, among many potential instances of running that program. Again, nothing specific to C, this terminology usually occurs in operating systems (which manage running of programs, and define what a "program" is).
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I was solving a practice problem on a site which states that
The purpose of this problem is to verify whether the method you are
using to read input data is sufficiently fast to handle problems
branded with the enormous Input/Output warning. You are expected to be
able to process at least 2.5MB of input data per second at runtime.
Also how do I optimize input/output routines other than printf and scanf?
It is operating system specific (because the C standard only knows about <stdio.h>). With Linux consider using low-level syscalls for efficiency, like open(2), mmap(2), read(2), pread(2), write(2). You might also want to use readahead(2). Don't forget to make I/O in rather large blocks (e.g. 128Kbytes), page aligned if possible. Read the Advanced Linux Programming book.
If restricted to standard C99 functions, use fread(3) on rather big chunks. Consider also increasing the internal buffer with setvbuf(3)
And 2.5Mbyte/sec is not very impressive. Probably, the bottleneck is the hardware, but you should be able to get perhaps 20 or 50Mbytes/sec on a standard desktop hardware. Using SSD would help a big lot.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am currently trying to write a program that will be able to create stable a TCP connection and have complete control over the ISN numbers. I've been writing in C and I am at a point where my very limited knowledge has reached its limits and I was wondering if there's a better way of doing it.
What I tried was building the headers manually, using raw sockets to send and recieve the packets without the kernel interfering, which is a challenge.
So regardless of language, what do you reckon is the most efficient and easiest way of manipulating the ISN?
Well, ISN is generatred in a random way to prevent ISN perediction attack (http://www.thegeekstuff.com/2012/01/tcp-sequence-number-attacks/).
The Linux Network stack, use the function tcp_v4_init_sequence to generate the ISN (http://lxr.free-electrons.com/source/net/ipv4/tcp_ipv4.c#L101), this function call secure_tcp_sequence_number function (http://lxr.free-electrons.com/source/net/core/secure_seq.c#L106) to do the job. Take a look at this function and try to clone it so can use it with your code from userspace.
If you have enough time you can look at section 3 of the RFC 6528 (http://www.rfc-editor.org/rfc/rfc6528.txt), it describe an algorithm on how to generate ISN:
ISN = M + F(localip, localport, remoteip, remoteport, secretkey)
And try to implement it, if you want :)
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I've been racking my brain at this all day and I just cannot figure it out. My server uses a single state that loads all of my scripts in as global variables (for calling any time without having to luaL_dofile each time I want to run a script). The problem comes in when I attempt to use lanes. require "lanes" works as it should (I think? It returns a table to package.loaded appropriately...) since I have the lanes.lua in the appropriate directory on Linux (Ubuntu 11.10 x86). However, when I go to do lanes.gen("", functionName) it tells me... attempt to index global 'lanes': a nil value. At this point I decided to try package.loaded["lanes"].gen("", functionName) and it tells me... attempt to index field 'gen': a nil value If you need more information, please let me know. Thank you in advance for at least trying to help.
If you are using the latest LuaLanes (which is what you get by luarocks install lanes), the supported way of loading the module is this:
local lanes = require "lanes".configure()
configure() will create all the necessary functions, before calling configure() the module table is empty, which seems like your issue.