Maybe the normal alignment in the vertex definition is off by one float size, that would (roughly) rotate it in certain circumstances.
[QUOTE=Tamschi;42808497]Maybe the normal alignment in the vertex definition is off by one float size, that would (roughly) rotate it in certain circumstances.[/QUOTE]
Are normals in VBOs always size 3? glNormalPointer doesn't take size so I assume it is 3. And I know my vertexes are size 3, which is how I specified them in my glVertexPointer call. After creating the buffer I've retrieved it with glMapBuffer and printed it out, the data is in the same order as the array I used to build it.
Sup FP,
I want to write a networked game but I don't know how I'd implement it.
As in I consider myself knowing about networking stuffs (TCP, UDP, protocols etc.) but I don't know how to apply it: send packets every timestep? what packets? how client and server talk to each other? and what do they say?
Previously I wrote some progs involving multiplaying but one is halfassed and other is copypaste, so they don't count.
Preferrably with some guidance for SDL_net, but anything would suffice, even chat application tutorial.
I think starting with some sort of simple board game or maybe tic-tac-toe is a good idea, since it doesn't involve frequent messaging and packets themselves will be quite simple.
[QUOTE=thrawn2787;42810442]Are normals in VBOs always size 3? glNormalPointer doesn't take size so I assume it is 3. And I know my vertexes are size 3, which is how I specified them in my glVertexPointer call. After creating the buffer I've retrieved it with glMapBuffer and printed it out, the data is in the same order as the array I used to build it.[/QUOTE]
Wouldn't it be 12, as in 3 4-byte-floats normally? I'm 90% sure it takes bytes as size units.
VBOs are just flat data, you can in theory have different sizes if you define the structs yourself. The pointer value is probably wrong if you calculated the offset with a position size of 3 instead of 12.
glNormalPointer looks like a fixed-function-pipeline function, if you switch to buffers you might as well go the extra step and use shaders (with GLSL 1.5 for maximum compatibility).
[editline]9th November 2013[/editline]
[QUOTE=vombatus;42810674]Sup FP,
I want to write a networked game but I don't know how I'd implement it.
As in I consider myself knowing about networking stuffs (TCP, UDP, protocols etc.) but I don't know how to apply it: send packets every timestep? what packets? how client and server talk to each other? and what do they say?
Previously I wrote some progs involving multiplaying but one is halfassed and other is copypaste, so they don't count.
Preferrably with some guidance for SDL_net, but anything would suffice, even chat application tutorial.
I think starting with some sort of simple board game or maybe tic-tac-toe is a good idea, since it doesn't involve frequent messaging and packets themselves will be quite simple.[/QUOTE]
For board games I'd just use TCP and send player commands, then you can use a background thread (Background's a special flag for threads that don't sustain the process.) to read the messages through blocking functions and put it somewhere the main thread can process it.
Make sure you flush the sockets, as TCP normally waits a bit for more data to send it in larger packets.
As long as you don't write invalid commands everything's fine, but it's difficult to recover from that in TCP because there's no quantization. You probably should just disconnect in that case, but you can recover by sending a special error and using a unique 'timing signature' signal to realign the packets. It shouldn't be an issue though as this will only happen with invalid programs or different program versions.
A downside of TCP is that you probably can't punch through NATs, for that you'd have to use UDP. Again, for a board game a stream socket is probably best because messages should arrive reliably and in order, but there are libraries that implement this on top of UDP.
[QUOTE=Tamschi;42811089]Wouldn't it be 12, as in 3 4-byte-floats normally? I'm 90% sure it takes bytes as size units.
VBOs are just flat data, you can in theory have different sizes if you define the structs yourself. The pointer value is probably wrong if you calculated the offset with a position size of 3 instead of 12.
glNormalPointer looks like a fixed-function-pipeline function, if you switch to buffers you might as well go the extra step and use shaders (with GLSL 1.5 for maximum compatibility).
[/QUOTE]
1) I am using shaders AND VBOs in the second picture. First uses neither. I am trying to use VBOs rather than calls to glVertex3f when using shaders.
2)
[quote]size
Specifies the number of coordinates per vertex. Must be 2, 3, or
4. The initial value is 4.
[/quote]
From [URL="http://www.opengl.org/sdk/docs/man2/xhtml/glVertexPointer.xml"]here[/URL]. So 3 is correct. glBufferData takes the size in bytes as a parameter, which I do.
Here's the shaders if you're curious
[code]// Toon vertex shader
// Should be used with toon.fsh
// Uses vertex normals and GL_LIGHT0 to compute intensity
// Passes intensity along to fragment shader
// Thanks to
// http://www.lighthouse3d.com/tutorials/glsl-tutorial/toon-shading/
varying float intensity;
void main()
{
vec3 lightDir = normalize(vec3(gl_LightSource[0].position));
intensity = dot(gl_Normal,lightDir);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}[/code]
[code]varying float intensity;
void main()
{
vec4 color;
if (intensity > 0.95)
color = vec4(1.0,0.5,0.5,1.0);
else if (intensity > 0.5)
color = vec4(0.6,0.3,0.3,1.0);
else if (intensity > 0.25)
color = vec4(0.4,0.2,0.2,1.0);
else
color = vec4(0.2,0.1,0.1,1.0);
gl_FragColor = color;
}[/code]
I don't mean the size parameter. The pointer parameter takes bytes too and if that one is wrong your light can rotate by 120° around the diagonal axis which would change it by 90° in your example.
[editline]9th November 2013[/editline]
It shouldn't rotate into that position though, so I have no clue what causes it.
Know of any libraries or .NET classes that will let me display a binary tree on a winform, and let me traverse and add nodes?
Yeah my call is
[code]// allocate the buffer
gl.glBufferData(gl.GL_ARRAY_BUFFER, Buffers.SIZEOF_FLOAT * fb.capacity(), fb, use);[/code]
So that looks right... plus the verticies seem to be correct since the shape displays correctly
So why is my php not doing anything?
[code]
<?php
function openFile()
{
$handle = fopen("./db.txt", "r");
if ($handle)
{
echo "SDF3333333r3232323";
while (($buffer = fgets($handle, 4096)) !== false)
{
echo $buffer;
}
if (!feof($handle))
{
echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}
else
{
echo "DSFSDF";
}
echo "SDFSeeeeF";
}
openFile();
echo "FUCK BALLS";
?>[/code]
nothing gets echoed in my html document containing this.
[QUOTE=twoski;42812726]So why is my php not doing anything?[/QUOTE]
I'd ask your host about enabling error reporting.
By the way, have a look at [url=http://us1.php.net/file_get_contents]file_get_contents[/url].
[QUOTE=thrawn2787;42812700]Yeah my call is
[code]// allocate the buffer
gl.glBufferData(gl.GL_ARRAY_BUFFER, Buffers.SIZEOF_FLOAT * fb.capacity(), fb, use);[/code]
So that looks right... plus the verticies seem to be correct since the shape displays correctly[/QUOTE]
Also I guess it doesn't have to do with the VBO... if I call the same function that renders that top picture but with the shader enabled (ie calling Vertex3f and Normal3f) I get the same result with the lighting being off.
edit: looks like the gl_LightSource[0].position was wrong. Set an attribute for the light position and passed it in instead and now it is correct. Problem is now it crashes VBOs...
[QUOTE=thrawn2787;42812700]Yeah my call is
[code]// allocate the buffer
gl.glBufferData(gl.GL_ARRAY_BUFFER, Buffers.SIZEOF_FLOAT * fb.capacity(), fb, use);[/code]
So that looks right... plus the verticies seem to be correct since the shape displays correctly[/QUOTE]
[del]What is use?
What do you call glNormalPointer with?
What data are you putting into the buffer?[/del]
[QUOTE=thrawn2787;42813173]Also I guess it doesn't have to do with the VBO... if I call the same function that renders that top picture but with the shader enabled (ie calling Vertex3f and Normal3f) I get the same result with the lighting being off.
edit: looks like the gl_LightSource[0].position was wrong. Set an attribute for the light position and passed it in instead and now it is correct. Problem is now it crashes VBOs...[/QUOTE]
Your posts aren't really helpful for finding the error, only for excluding specific ones.
You really should post a bit more of the code you have so it becomes possible to see the exact mistake.
[QUOTE=Tamschi;42813768][del]What is use?
What do you call glNormalPointer with?
What data are you putting into the buffer?[/del]
Your posts aren't really helpful for finding the error, only for excluding specific ones.
You really should post a bit more of the code you have so it becomes possible to see the exact mistake.[/QUOTE]
Yeah sorry about that. I can ask someone for help irl Monday. Thanks for the help though.
Can someone explain Java delimiters real quick? I'm like 80% sure I know what they are but I'm tired so I'm not positive. I should probably get some sleep but I figured I'd ask first.
[[B]C++[/B]] I need help with a question I do not understand.
Here is a code:
[CODE]#include <iostream>
int main()
{
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2 << " = " << v1 + v2 << std::endl;
system("pause");
return 0;
}
[/CODE]
[B]I'm then asked to do this:[/B]
[QUOTE]We wrote the output in one large statement. Rewrite the
program to use a separate statement to print each operand.[/QUOTE]
[B]Then I did this:[/B]
[CODE]#include <iostream>
int main()
{
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The number " << std::endl;
std::cout << v1 << std::endl;
std::cout << "and the number " << std::endl;
std::cout << v2 << std::endl;
std::cout << "equals " << std::endl;
std::cout << v1 + v2 << std::endl;
system("pause");
return 0;
}}[/CODE]
[B]Is that correct? If not, how do I do this?[/B]
[QUOTE=Zinayzen;42816213]Can someone explain Java delimiters real quick? I'm like 80% sure I know what they are but I'm tired so I'm not positive. I should probably get some sleep but I figured I'd ask first.[/QUOTE]
A delimiter determines where something should stop reading text input. The default Scanner delimiter is a space (whitespace), you can edit this to whatever you want. Examples:
[url]http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html[/url]
[cpp]
String input = "1 fish 2 fish red fish blue fish";
Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*");
System.out.println(s.nextInt());
System.out.println(s.nextInt());
System.out.println(s.next());
System.out.println(s.next());
s.close();
[/cpp]
Output:
[cpp]
1
2
red
blue
[/cpp]
[editline]10th November 2013[/editline]
[QUOTE=Aesthetics;42817217][[B]C++[/B]] I need help with a question I do not understand.
Here is a code:
[CODE]#include <iostream>
int main()
{
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2 << " = " << v1 + v2 << std::endl;
system("pause");
return 0;
}
[/CODE]
[B]I'm then asked to do this:[/B]
[B]Then I did this:[/B]
[CODE]#include <iostream>
int main()
{
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The number " << std::endl;
std::cout << v1 << std::endl;
std::cout << "and the number " << std::endl;
std::cout << v2 << std::endl;
std::cout << "equals " << std::endl;
std::cout << v1 + v2 << std::endl;
system("pause");
return 0;
}}[/CODE]
[B]Is that correct? If not, how do I do this?[/B][/QUOTE]
That looks to be correct.
[QUOTE=mobrockers;42817588]A delimiter determines where something should stop reading text input. The default Scanner delimiter is a space (whitespace), you can edit this to whatever you want. Examples:
[url]http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html[/url]
[cpp]
String input = "1 fish 2 fish red fish blue fish";
Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*");
System.out.println(s.nextInt());
System.out.println(s.nextInt());
System.out.println(s.next());
System.out.println(s.next());
s.close();
[/cpp]
Output:
[cpp]
1
2
red
blue
[/cpp]
[editline]10th November 2013[/editline]
That looks to be correct.[/QUOTE]
Alright, thank you for confirming!
[QUOTE=Aesthetics;42817217][[B]C++[/B]] I need help with a question I do not understand.
Here is a code:
[CODE]#include <iostream>
int main()
{
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2 << " = " << v1 + v2 << std::endl;
system("pause");
return 0;
}
[/CODE]
[B]I'm then asked to do this:[/B]
[B]Then I did this:[/B]
[CODE]#include <iostream>
int main()
{
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The number " << std::endl;
std::cout << v1 << std::endl;
std::cout << "and the number " << std::endl;
std::cout << v2 << std::endl;
std::cout << "equals " << std::endl;
std::cout << v1 + v2 << std::endl;
system("pause");
return 0;
}}[/CODE]
[B]Is that correct? If not, how do I do this?[/B][/QUOTE]
No it isn't.
See for yourself: Original line:
[cpp]std::cout << "The sum of " << v1 << " and " << v2 << " = " << v1 + v2 << std::endl;[/cpp]
Let's break it apart: it prints
[b]"The sum of "[/b], [B]value v1[/B], string [B]" and "[/B], .. etc .. [B]sum of values v1 and v2[/B] and newline.
thus, result that will be printed is (assuming we entered 1 and 2) "The sum of 1 and 2 = 3" and a newline,
What your version does is:
[B]"The number of "[/B], [b]newline[/b], [b]value v1[/b], [b]newline[/b], ..
See your error? If not, that what it prints:
"The number
1
and the number
2
equals
3"
You don't have to append std::endl at the end of every std::cout, it adds that newline character and thus printing starts on next line.
By the way I don't get why did you modify original "The sum of" message. Also if you ran it, you'd see the error immediately.
[QUOTE=vombatus;42817922]No it isn't.
See for yourself: Original line:
[code]std::cout << "The sum of " << v1 << " and " << v2 << " = " << v1 + v2 << std::endl;[/cpp]
Let's break it apart: it prints
[b]"The sum of "[/b], [B]value v1[/B], string [B]" and "[/B], .. etc .. [B]sum of values v1 and v2[/B] and newline.
thus, result that will be printed is (assuming we entered 1 and 2) "The sum of 1 and 2 = 3" and a newline,
What your version does is:
[B]"The number of "[/B], [b]newline[/b], [b]value v1[/b], [b]newline[/b], ..
See your error? If not, that what it prints:
"The number
1
and the number
2
equals
3"
You don't have to append std::endl at the end of every std::cout, it adds that newline character and thus printing starts on next line.
By the way I don't get why did you modify original "The sum of" message. Also if you ran it, you'd see the error immediately.[/QUOTE]
I started C++ today, so I'm kinda new to this whole thing, but thanks for putting it out there.
C#, trying to read a registry key with [url]http://www.codeproject.com/Articles/3389/Read-write-and-delete-from-registry-with-C[/url]
[code]
ModifyRegistry myRegistry = new ModifyRegistry();
myRegistry.ShowError = true;
myRegistry.SubKey = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles\\0001";
string regA = myRegistry.Read("HwProfileGuid");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine(" Value retrieved");
Console.WriteLine(" Writing");
string filename = "r.txt";
using (System.IO.StreamWriter writeFile = new System.IO.StreamWriter(filename, true))
{
writeFile.Write(regA);
}
[/code]
The file is empty, what I'm doing wrong?
[QUOTE=Liota;42818455]C#, trying to read a registry key with [url]http://www.codeproject.com/Articles/3389/Read-write-and-delete-from-registry-with-C[/url]
[code]
using Microsoft.Win32;
...
string RegContent = "";
string Key = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles\\0001";
string Value = "HwProfileGuid";
RegContent = Registry.GetValue(Key, Value, "").ToString();
using (System.IO.StreamWriter writeFile = new System.IO.StreamWriter("reg.txt", true)) {
Console.WriteLine("Writing: \"{0}\"", RegContent);
writeFile.Write(RegContent);
}
[/code]
[editline]10th November 2013[/editline]
Don't use some random classes, Microsoft.Win32.Registry works just well for what you need.
[sp]Ignore broken quote[/sp]
[QUOTE=cartman300;42818655][QUOTE=Liota;42818455]C#, trying to read a registry key with [url]http://www.codeproject.com/Articles/3389/Read-write-and-delete-from-registry-with-C[/url]
[code]
using Microsoft.Win32;
...
string RegContent = "";
string Key = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles\\0001";
string Value = "HwProfileGuid";
RegContent = Registry.GetValue(Key, Value, "").ToString();
using (System.IO.StreamWriter writeFile = new System.IO.StreamWriter("reg.txt", true)) {
Console.WriteLine("Writing: \"{0}\"", RegContent);
writeFile.Write(RegContent);
}
[/code]
[editline]10th November 2013[/editline]
Don't use some random classes, Microsoft.Win32.Registry works just well for what you need.
[sp]Ignore broken quote[/sp][/QUOTE]
Thanks, worked.
I never understood how exactly large websites can stay fast.
For example YouTube or facebook.
I think there has to be some [B]central[/B] database-server.
But how can it handle hundrets of thousands of connections and requests at the same time?
The only way I can think of this could work would be to do load balancing. But that requires multiple databases, does it not?
And if they use some sort of non-central database then how do they avoid the usual concurrency issues (people editing posts that have already been deleted, ...)
[QUOTE=Felheart;42826118]I never understood how exactly large websites can stay fast.
For example YouTube or facebook.
I think there has to be some [B]central[/B] database-server.
But how can it handle hundrets of thousands of connections and requests at the same time?
The only way I can think of this could work would be to do load balancing. But that requires multiple databases, does it not?
And if they use some sort of non-central database then how do they avoid the usual concurrency issues (people editing posts that have already been deleted, ...)[/QUOTE]
You might still be able to edit a post that's already been deleted, but it won't be submitted to the database because it checks for these things before sending anything, and Facebook then tells you that the message no longer exists.
But yeah, they use concurrent systems. A lot of the tools Facebook use are available as open source software, and if you're interrested in these things, you should totally check it out.
snip
Does anyone know why this isn't working?
[cpp]using System;
using System.IO;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
namespace GLTest
{
class Program
{
private static GameWindow window;
private static int shaderProgram;
private static uint vbo;
private static uint vao;
static void Main(string[] args)
{
window = new GameWindow(800, 480);
window.Load += Initialize;
window.UpdateFrame += Update;
window.RenderFrame += Render;
window.Run(60);
}
private static void Initialize(object sender, EventArgs e)
{
GL.ClearColor(Color4.Black);
float[] vertices = new float[]
{
0f, 0.5f,
0.5f, -0.5f,
-0.5f, -0.5f
};
GL.GenVertexArrays(1, out vao);
GL.BindVertexArray(vao);
GL.GenBuffers(1, out vbo);
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(vertices.Length), vertices, BufferUsageHint.StaticDraw);
var vertexSource = File.ReadAllText("VertexShader.fx");
var fragmentSource = File.ReadAllText("FragmentShader.fx");
int vertexShader = GL.CreateShader(ShaderType.VertexShader);
GL.ShaderSource(vertexShader, vertexSource);
GL.CompileShader(vertexShader);
VerifyShader(vertexShader, "Vertex");
int fragmentShader = GL.CreateShader(ShaderType.FragmentShader);
GL.ShaderSource(fragmentShader, fragmentSource);
GL.CompileShader(fragmentShader);
VerifyShader(fragmentShader, "Fragment");
shaderProgram = GL.CreateProgram();
GL.AttachShader(shaderProgram, vertexShader);
GL.AttachShader(shaderProgram, fragmentShader);
GL.BindFragDataLocation(shaderProgram, 0, "outColor");
GL.LinkProgram(shaderProgram);
GL.UseProgram(shaderProgram);
int positionAttribute = GL.GetAttribLocation(shaderProgram, "position");
GL.VertexAttribPointer(positionAttribute, 2, VertexAttribPointerType.Float, false, 0, 0);
GL.EnableVertexAttribArray(positionAttribute);
}
private static void Update(object sender, FrameEventArgs e)
{
}
private static void Render(object sender, FrameEventArgs e)
{
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.DrawArrays(BeginMode.Triangles, 0, 3);
window.SwapBuffers();
}
private static void VerifyShader(int shader, string id)
{
int result;
GL.GetShader(shader, ShaderParameter.CompileStatus, out result);
string info = GL.GetShaderInfoLog(shader);
if (result == 1)
{
Console.WriteLine(id + " shader successfully compiled (" + info + ")");
}
else
{
Console.WriteLine(id + " shader failed to compile (" + info + ")");
}
}
}
}[/cpp]
[img]http://u.rtag.me/skippy/OXTNRege.png[/img]
[editline]11th November 2013[/editline]
Fragment shader
[cpp]#version 150
out vec4 outColor;
void main()
{
outColor = vec4(1.0, 1.0, 1.0, 1.0);
}[/cpp]
Vertex shader
[cpp]#version 150
in vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}[/cpp]
[QUOTE=Dj-J3;42827867]Does anyone know why this isn't working?
[...][/QUOTE]
Just guessing, but maybe you have to set something after binding the shader that you set before doing that.
I vaguely remember having a similar problem.
[QUOTE=Dj-J3;42827867]Does anyone know why this isn't working?
[/QUOTE]
Your VBO isn't big enough, multiply the lenght of the array with the size of a float like this:
[cpp]GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(vertices.Length * sizeof(float)), vertices, BufferUsageHint.StaticDraw);[/cpp]
[QUOTE=Zeonho;42828366]Your VBO isn't big enough, multiply the lenght of the array with the size of a float like this:
GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(vertices.Length * sizeof(float)), vertices, BufferUsageHint.StaticDraw);
[/QUOTE]
It works! Thanks, can't believe i missed that. :v:
[img]http://u.rtag.me/skippy/ko61AJ1e.png[/img]
What would be the best type of program to make to show off my skills to a college?
Sorry, you need to Log In to post a reply to this thread.