[QUOTE=LuaGuy;34025610]well i stuck for a while, i wanna make a program with 5 column of numbers and wanna increase them whenever the user input's a number from 1 to 5 for example if the user enters 2 it will increase all of the numbers by 2. but im stuck at returning from queryFunc to main function. and without it program cant keep working. if i can do this i will add the else statement and finish my job. hope you guys can help me im a little bit beginner in C++
[cpp]#include <iostream>
using namespace std;
void drawFunc();
void askFunc();
void queryFunc();
int main()
{
int x = 1;
drawFunc();
askFunc();
queryFunc();
return 0;
}
void drawFunc()
{
int x = 1;
while(x <= 5)
{
cout << x << "|" << x << "|" << x << "|" << x << "|" << x << endl;
x = x++;
}
}
void askFunc()
{
int x = 1;
cout << "Enter a number from 1 to 5: ";
cin >> x;
}
void queryFunc()
{
int x = 1;
if(x == 2 | 3 | 4 | 5)
{
/* i wanna return to the main function from here
but i cant as i said above.
*/
}
}[/cpp]
also defining same variable in all functions is weird i dont know how i can shorten it also is there a way to make the columns dynamic without need for go down ?[/QUOTE]
I think this will work:
[cpp]#include <iostream>
using namespace std;
void drawFunc(int x);
void askFunc();
int main()
{
int x = 1;
while(true)
{
drawFunc(x);
x += askFunc(); //adds to the current value of x
}
return 0;
}
void drawFunc(int x) //print five rows of five columns, each row with five columns of x plus 1 to 5.
{
int i = 1;
while(i <= 5)
{
cout << x + i << "|" << x + i << "|" << x + i << "|" << x + i << "|" << x + i << endl;
i++ //increment
}
}
void askFunc()
{
int x = 0;
cout << "Enter a number from 1 to 5: ";
cin >> x;
if((x == 1 || x == 2 || x == 3 || x == 4 || x == 5) == false) //not 1-5?
{
cout << "Not a valid number.";
x = 0; //don't add anything
}
return x;
}[/cpp]
[editline]2nd January 2012[/editline]
The queryFunc wasn't really necessary, and you were initializing x as 1 locally in each function.
[QUOTE=ZenX2;34025949]I think this will work:
[cpp]#include <iostream>
using namespace std;
void drawFunc(int x);
void askFunc();
int main()
{
int x = 1;
while(true)
{
drawFunc(x);
x += askFunc(); //adds to the current value of x
}
return 0;
}
void drawFunc(int x) //print five rows of five columns, each row with five columns of x plus 1 to 5.
{
int i = 1;
while(i <= 5)
{
cout << x + i << "|" << x + i << "|" << x + i << "|" << x + i << "|" << x + i << endl;
i++ //increment
}
}
void askFunc()
{
int x = 0;
cout << "Enter a number from 1 to 5: ";
cin >> x;
if((x == 1 || x == 2 || x == 3 || x == 4 || x == 5) == false) //not 1-5?
{
cout << "Not a valid number.";
x = 0; //don't add anything
}
return x;
}[/cpp]
[editline]2nd January 2012[/editline]
The queryFunc wasn't really necessary, and you were initializing x as 1 locally in each function.[/QUOTE]
In function 'int main()':|
error: void value not ignored as it ought to be|
in evaluation of 'operator+=(int, void)'|
In function 'void drawFunc(int)':|
|28|error: expected ';' before '}' token|
In function 'void askFunc()':|
|41|error: return-statement with a value, in function returning 'void'|
||=== Build finished: 4 errors, 0 warnings ===|
thanks for your interest but it gives bunch of errors ?
Is this any better?
[cpp]#include <iostream>
using namespace std;
void drawFunc(int x);
int askFunc(); //was void
int main()
{
int x = 1;
while(true)
{
drawFunc(x);
x += askFunc(); //adds to the current value of x
}
return 0;
}
void drawFunc(int x) //print five rows of five columns, each row with five columns of x plus 1 to 5.
{
int i = 1;
while(i <= 5)
{
cout << x + i << "|" << x + i << "|" << x + i << "|" << x + i << "|" << x + i << endl;
i++; //increment //forgot the semicolon
}
}
int askFunc() //was void
{
int x = 0;
cout << "Enter a number from 1 to 5: ";
cin >> x;
if((x == 1 || x == 2 || x == 3 || x == 4 || x == 5) == false) //not 1-5?
{
cout << "Not a valid number.";
x = 0; //don't add anything
}
return x;
}[/cpp]
Although you should compare both to learn how to identify those types of errors
I'm trying to use Awesonium to render to a ID3D11Texture2D (or associated ID3D11ShaderResourceView).
I've gone through the steps of setting up Awesonium and rendering, and then I use this code:
[cpp]
//Copy to buffer
const awe_renderbuffer *renderBuffer = awe_webview_render(webView);
if(renderBuffer)
{
//Copy buffer to texture
unsigned char *myBuffer;
myBuffer = new unsigned char[512*512*4];
awe_renderbuffer_copy_to(renderBuffer, myBuffer, 512 * 4, 4, true, false);
Renderer()->BindDynamicTexture2D(myBuffer);
delete[] myBuffer;
}
[/cpp]
(Unfortunately I have to use the C API for Awesonium due to using Visual Studio 2010).
Where Renderer()->BindDynamicTexture2D is:
[cpp]
void RenderSystem::BindDynamicTexture2D(unsigned char *buffer)
{
//Map it
D3D11_MAPPED_SUBRESOURCE ms;
GetRenderBackend()->m_pDeviceContext->Map(m_pTexture2D, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
memcpy(ms.pData, buffer, sizeof(buffer));
GetRenderBackend()->m_pDeviceContext->Unmap(m_pTexture2D, NULL);
//Re-bind it
HRESULT result = GetRenderBackend()->m_pDevice->CreateShaderResourceView(m_pTexture2D, NULL, &m_pDynamic2DView);
}
[/cpp]
Where m_pTexture2D is made by:
[cpp]
//Create our 'dynamic' texture
D3D11_TEXTURE2D_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.Width = 512;
desc.Height = 512;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.Usage = D3D11_USAGE_DYNAMIC;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
desc.SampleDesc.Count = 1;
GetRenderBackend()->m_pDevice->CreateTexture2D(&desc, NULL, &m_pTexture2D);
[/cpp]
I then try to bind the m_pDynamic2DView to the shader and draw it on a quad. Unfortunately it just displays black. If I bind a normal texture loaded from file, it shows up fine.
"HRESULT result = GetRenderBackend()->m_pDevice->CreateShaderResourceView(m_pTexture2D, NULL, &m_pDynamic2DView);" returns S_OK; so I think it copied the data okay, but it's obviously wrong.
Anyone have any experience with either Awesonium or dynamic-usage ID3D11Texture2D's?
I'm working on FPS camera control, what would be the simplest way to turn the mouse difference from the center (X and Y values) into the proper rotations?
[QUOTE=Lord Ned;34028136]Where Renderer()->BindDynamicTexture2D is:
[cpp]
void RenderSystem::BindDynamicTexture2D(unsigned char *buffer)
{
//Map it
D3D11_MAPPED_SUBRESOURCE ms;
GetRenderBackend()->m_pDeviceContext->Map(m_pTexture2D, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
memcpy(ms.pData, buffer, sizeof(buffer));
GetRenderBackend()->m_pDeviceContext->Unmap(m_pTexture2D, NULL);
//Re-bind it
HRESULT result = GetRenderBackend()->m_pDevice->CreateShaderResourceView(m_pTexture2D, NULL, &m_pDynamic2DView);
}
[/cpp][/QUOTE]
sizeof(buffer) is the size of the pointer. Send the actual size as another parameter. Also you shouldn't need to create another view.
[QUOTE=Hypershadsy;34025011]Except they still aren't even after I seed it in love.load().[/QUOTE]
[img]http://puu.sh/ci1B[/img]
[QUOTE=ZenX2;34026862]Is this any better?
[cpp]#include <iostream>
using namespace std;
void drawFunc(int x);
int askFunc(); //was void
int main()
{
int x = 1;
while(true)
{
drawFunc(x);
x += askFunc(); //adds to the current value of x
}
return 0;
}
void drawFunc(int x) //print five rows of five columns, each row with five columns of x plus 1 to 5.
{
int i = 1;
while(i <= 5)
{
cout << x + i << "|" << x + i << "|" << x + i << "|" << x + i << "|" << x + i << endl;
i++; //increment //forgot the semicolon
}
}
int askFunc() //was void
{
int x = 0;
cout << "Enter a number from 1 to 5: ";
cin >> x;
if((x == 1 || x == 2 || x == 3 || x == 4 || x == 5) == false) //not 1-5?
{
cout << "Not a valid number.";
x = 0; //don't add anything
}
return x;
}[/cpp]
Although you should compare both to learn how to identify those types of errors[/QUOTE]
thank you very much
Windows. I'll do some testing, brb
-snop-
I did some tests and found that the first random number generated in a sequence of math.random()'s is always the same. I generated 8 numbers, using different seeds, and the first is always the same. I think I'd have to make a trash variable to catch that first one.
I'm writing little Java console app that must do SOAP RPCs. Can't find any good examples how to write simple Java SOAP client. Can anyone help me? =(
In SFML, can I draw only the outline of a circle without filling it?
[editline]3rd January 2012[/editline]
Never mind... I found out.
[QUOTE=Hypershadsy;34036400]I did some tests and found that the first random number generated in a sequence of math.random()'s is always the same. I generated 8 numbers, using different seeds, and the first is always the same. I think I'd have to make a trash variable to catch that first one.[/QUOTE]
Not happening here...
[img]http://i.imgur.com/KtpKc.png[/img]
[QUOTE=Philly c;34030153]sizeof(buffer) is the size of the pointer. Send the actual size as another parameter. Also you shouldn't need to create another view.[/QUOTE]
Derp derp derp derp.
That's what I get for programming late at night.
I've never been happier to see Google's page. :v:
[img]http://i55.tinypic.com/w2li52.png[/img]
Anyone have any ideas on creating text commands for a C# console application. For example I could type exit into the console, hit enter, and have it perform an application. I am not sure if I need an external library or if .NET has some sort of solution.
What's the best way to store level data?
[QUOTE=Mr. Smartass;34041270]What's the best way to store level data?[/QUOTE]
What kind of level data? You need to be more specific.
[QUOTE=CmdrMatthew;34042502]What kind of level data? You need to be more specific.[/QUOTE]
Gah, I really should have been more specific. I meant 3d level data. Would it be practical to have a mesh-based terrain and buildings, or would my best bet to make something that would make ground and walls from triangle strips and the like?
Some kind of XML or XML like file format, if your game is simple and just needs to load tiles CSV can be easiest.
Games like Halo compile a model file and that becomes the level.
[QUOTE=Vbits;34042985]Some kind of XML or XML like file format, if your game is simple and just needs to load tiles CSV can be easiest.
Games like Halo compile a model file and that becomes the level.[/QUOTE]
Thank ye kindly
[QUOTE=Shane;34039846]Anyone have any ideas on creating text commands for a C# console application. For example I could type exit into the console, hit enter, and have it perform an application. I am not sure if I need an external library or if .NET has some sort of solution.[/QUOTE]
Console.ReadLine().Split(" ");
[QUOTE=dvondrake;34045361]Working on a deferred renderer. Normals are in view space so I can omit Z and reconstruct it later to make my G-buffer smaller. That's working fine, however I'm having an issue with adding lights in view space.
[img.]http://i.imgur.com/5rcE5.png[/img]
I'm passing the light's position as a uniform. It's my understanding that when lighting in view space I just need to transform the light's position by the modelview matrix, but this doesn't seem to work. The lighting still appears to move around with my camera, and it seems kind of inverted positionally. I really have no clue how to fix this. Am I doing the light position in view space wrong? Or are the normals fucked one way or another? Maybe I'm getting the position wrong regarding view space? Or is the lighting equation in my shader incorrect? I'm truly lost. I'll start debugging this tomorrow, but a poke in the right direction would be highly appreciated.
Here's my shader (GLSL):
[code]-snip-
[/code]
I'm even starting to wonder if saving the normals in view space is really all that worth it--besides less data in the G-buffer, what other pros & cons are there?
Either way, any ideas on how to fix this? Help would be very much appreciated, as I have absolutely no clue on any leads to follow in order to fix this.[/QUOTE]
It looks like you're defining light as the transpose of the modelviewprojection matrix instead of the inverse transpose of the modelview matrix. That's probably your issue. Also in case you didn't notice, you're setting your camera to (0, 0, 0) instead passing it in as a uniform.
Also view space normals are one of the main benefits from deferred rendering as lighting goes from a O(M * N) operation to an O(M + N) operation, where M are rendered objects and N are lights. Normal mapping among several things become much easier to do.
You can store depth as the alpha channel of another buffer if you're not already doing that, but there's no way of being able to infer any data about normals from depth or vice-versa.
How would i load a text file in XNA? Do i have to place it in the content files or the project file and how do i load it? And after that, how to read the lines of it?
[QUOTE=Funley;34046642]How would i load a text file in XNA? Do i have to place it in the content files or the project file and how do i load it? And after that, how to read the lines of it?[/QUOTE]
Look into StreamReader you basically give it a path and it lets you read from the file.
[url]http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx[/url]
How I make a 3D square rotate towards to a given position, like a sprite?
Used this to draw it:
[cpp]
float Positionx = 10;
float Positiony = 1;
float Positionz = 20;
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(1.0f,1.0f); glVertex3f(-1.0f, 1.0f,-1.0f);
glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f,-1.0f,-1.0f);
glTexCoord2f(1.0f,0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,-1.0f, 1.0f);
glEnd();
[/cpp]
[QUOTE=reevezy67;34046725]Look into StreamReader you basically give it a path and it lets you read from the file.
[url]http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx[/url][/QUOTE] I get the error "A namespace cannot directly contain members such as fields or methods" in the text file in the project folder. What?
[QUOTE=Funley;34046788]I get the error "A namespace cannot directly contain members such as fields or methods" in the text file in the project folder. What?[/QUOTE]
Pretty sure that happens when you wrote some code outside a class or method definition.
Mind posting the code?
[QUOTE=reevezy67;34046881]Pretty sure that happens when you wrote some code outside a class or method definition.
Mind posting the code?[/QUOTE] This is the text file i use: [code] - <NAME_TITLE_HERE>
- 64 bit graphics hell yeah!
- !smooth moving
- Fat player!
- One hundred kilograms of pixels
- Not wet
- No modding![/code] And this is the code i use to load and read it: [code]try
{
using (StreamReader sr = new StreamReader("titles.txt"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
additionalTitle[0] = line;
Console.WriteLine("Loaded " + line + " from titles.txt");
}
}
}
catch (Exception e)
{
Console.WriteLine("Title loading failed. " + e.Message);
Console.WriteLine("Press Enter to continue");
Console.ReadLine();
Exit();
}[/code]
And the error is in the text file. I think Visual Studio tries to compile it as code.
Nothing wrong with that from what I can see.
it's obviously something wrong with your placement of some code or even a random key you didn't mean to press.
Like how this returns the error you get.
[csharp]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
HI HERE IS THE ERROR
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}[/csharp]
Sorry, you need to Log In to post a reply to this thread.