Anyone mind telling me if this draws anything other than a red screen? [url]http://db.tt/cA04eKaQ[/url]
Just a red screen for me.
[QUOTE=Richy19;37271318]Anyone mind telling me if this draws anything other than a red screen? [url]http://db.tt/cA04eKaQ[/url][/QUOTE]
[url=http://bit.ly/RXlsBL]Segfaults for me.[/url] :v:
[QUOTE=Richy19;37271318]Anyone mind telling me if this draws anything other than a red screen? [url]http://db.tt/cA04eKaQ[/url][/QUOTE]
Crashes with an exception.
[img]http://puu.sh/VWh8[/img]
I'm running on GTX560 Ti, latest beta drivers.
ARGHHHHHHH god damn ittttt, I have no idea why this is happening.
Heres the source if anyone is bored and has a free moment :( Im giving up on programming for the next hour going for dinner instead
I sware once i get back to my desktop im just going to use slimDX...
[url]http://dl.dropbox.com/u/18453712/opentkgaem.zip[/url]
Red screen, no crash when I compile it myself :v:
[quote]Alright, have you already built and placed GLFW in the correct folder (include and lib directories)?[/quote]
What do you mean by built?
[QUOTE=Richy19;37271318]Anyone mind telling me if this draws anything other than a red screen? [url]http://db.tt/cA04eKaQ[/url][/QUOTE]
No problem, it draws a dropbox 404 file not found error :v:
[QUOTE=Topgamer7;37274243]No problem, it draws a dropbox 404 file not found error :v:[/QUOTE]
My bad deleted it when i uploaded the source
[editline]16th August 2012[/editline]
[QUOTE=raBBish;37273432]Red screen, no crash when I compile it myself :v:[/QUOTE]
I removed the skybox and added text, styll i take it its not showing
Am I right in understanding that it's generally a good practise to keep graphics renderers separate from the application so you can switch between an openGL/DX renderer for example?
Surelly with this ortho setup:
MVP = Matrix4.CreateOrthographicOffCenter(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 2.0f);
where the screen is:
[code]
0 - 0 1 - 0
----------------------------------------------
| |
| |
| |
| |
| |
---------------------------------------------
0 - 1 1 - 1
[/code]
And these verticies:
[csharp]
float[] vertices = { 0.5f, 0.0f, 1.0f,
0.0f, -1.0f, 1.0f,
1.0f, 1.0f, 1.0f };
[/csharp]
The triangle should be right in the midle of the screen, well for some reason it isnt.
I know that its drawing it because I got the triangle to draw earlier when I was using just the x,y of the verticies but changing the size of GL.VertexAttribPointer from 2 to 3 has made it not draw anymore.
Heres all the code encase its something other than positioning
[csharp]// Released to the public domain. Use, modify and relicense at will.
using System;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Audio;
using OpenTK.Audio.OpenAL;
using OpenTK.Input;
namespace StarterKit
{
class Game : GameWindow
{
float[] vertices = { 0.5f, 0.0f, 1.0f,
0.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f };
int vbo;
string fragmentSource = "#version 120\n" +
"void main(){gl_FragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);}";
string vertexSource = "#version 120 \n" +
"uniform mat4 MVP; attribute vec4 Position;" +
"void main(){ gl_Position = MVP * Position; }";
int shaderProgram, vertexShader, fragmentShader;
int MVPID, PositionID;
Matrix4 MVP;
/// <summary>Creates a 800x600 window with the specified title.</summary>
public Game ()
: base(800, 600, GraphicsMode.Default, "OpenTK Quick Start Sample")
{
VSync = VSyncMode.On;
}
protected override void OnDisposed(EventArgs e)
{
GL.DetachShader( shaderProgram, vertexShader );
GL.DetachShader( shaderProgram, fragmentShader );
GL.DeleteShader(vertexShader);
GL.DeleteShader(fragmentShader);
GL.DeleteProgram(shaderProgram);
GL.DeleteBuffers(1, ref vbo);
base.OnDisposed(e);
}
/// <summary>Load resources here.</summary>
/// <param name="e">Not used.</param>
protected override void OnLoad (EventArgs e)
{
base.OnLoad (e);
GL.ClearColor (0.1f, 0.2f, 0.5f, 0.0f);
GL.Enable (EnableCap.DepthTest);
GL.GenBuffers (1, out vbo);
GL.BindBuffer (BufferTarget.ArrayBuffer, vbo);
GL.BufferData (BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * sizeof(float)), vertices, BufferUsageHint.StaticDraw);
vertexShader = GL.CreateShader(ShaderType.VertexShader);
GL.ShaderSource( vertexShader, vertexSource );
GL.CompileShader( vertexShader );
fragmentShader = GL.CreateShader( ShaderType.FragmentShader );
GL.ShaderSource( fragmentShader, fragmentSource );
GL.CompileShader( fragmentShader );
shaderProgram = GL.CreateProgram();
GL.AttachShader( shaderProgram, vertexShader );
GL.AttachShader( shaderProgram, fragmentShader );
GL.LinkProgram(shaderProgram);
MVPID = GL.GetUniformLocation(shaderProgram, "MVP");
PositionID = GL.GetAttribLocation(shaderProgram, "Position");
MVP = Matrix4.CreateOrthographicOffCenter(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 2.0f);
}
/// <summary>
/// Called when your window is resized. Set your viewport here. It is also
/// a good place to set up your projection matrix (which probably changes
/// along when the aspect ratio of your window).
/// </summary>
/// <param name="e">Not used.</param>
protected override void OnResize (EventArgs e)
{
base.OnResize (e);
GL.Viewport (ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
}
/// <summary>
/// Called when it is time to setup the next frame. Add you game logic here.
/// </summary>
/// <param name="e">Contains timing information for framerate independent logic.</param>
protected override void OnUpdateFrame (FrameEventArgs e)
{
base.OnUpdateFrame (e);
if (Keyboard [Key.Escape])
Exit ();
}
/// <summary>
/// Called when it is time to render the next frame. Add your rendering code here.
/// </summary>
/// <param name="e">Contains timing information.</param>
protected override void OnRenderFrame (FrameEventArgs e)
{
base.OnRenderFrame (e);
GL.Clear (ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.UseProgram (shaderProgram);
GL.UniformMatrix4(MVPID, false, ref MVP);
GL.EnableVertexAttribArray(PositionID);
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
GL.VertexAttribPointer(PositionID, 3, VertexAttribPointerType.Float, false, 0, IntPtr.Zero);
GL.DrawArrays(BeginMode.Triangles, 0, 3);
GL.DisableVertexAttribArray(PositionID);
GL.UseProgram (0);
SwapBuffers ();
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main ()
{
// The 'using' idiom guarantees proper resource cleanup.
// We request 30 UpdateFrame events per second, and unlimited
// RenderFrame events (as fast as the computer can handle).
using (Game game = new Game()) {
game.Run (30.0);
}
}
}
}[/csharp]
[QUOTE=Tamschi;37252475]Apparently it's possible to use the projection matrix for this. I'll try it and post the code if it works.
[editline]:([/editline]
...or not. My computer just broke.[/QUOTE]
I tried to use this: [URL="http://www.terathon.com/code/oblique.html"]http://www.terathon.com/code/oblique.html[/URL]
It doesn't work though, for some reason. I think I'll try using a second depth buffer, if I continue working on the mirror, mostly for the arbitrary surface that should be possible that way.
I'd like some help on making a timer of some sort using Processing, if anyone knows what that is.
[QUOTE=lawlavex;37294337]I'd like some help on making a timer of some sort using Processing, if anyone knows what that is.[/QUOTE]
Is this what you mean?
[url]http://processing.org/reference/second_.html[/url]
[QUOTE=ECrownofFire;37294399]Is this what you mean?
[url]http://processing.org/reference/second_.html[/url][/QUOTE]
[url]http://processing.org/reference/millis_.html[/url] might be more useful. millis() returns the number of ms since the applet started, but second() returns the seconds count for the current minute.
I have a number that I need to select a random '1' bit from as quickly as possible.
The naive solution of course is to iterate over each bit, add the '1' bits to an array or something and then pick a random one from there.
But that is cumbersome and slow, and I'd like a better solution. I tried something like this:
[cpp]int pickRandomBit(int n, int numBits)
{
int bitPos = rand() % numBits;
unsigned int mask = ~((1 << bitPos) - 1);
if(mask & n) n &= mask;
return n - (n & (n - 1));
}[/cpp]
But this heavily favours the lower significance bits. I need something that has a much more even probability of selecting each bit.
[QUOTE=Chris220;37302689]I have a number that I need to select a random '1' bit from as quickly as possible.
The naive solution of course is to iterate over each bit, add the '1' bits to an array or something and then pick a random one from there.
But that is cumbersome and slow, and I'd like a better solution. I tried something like this:
[cpp]int pickRandomBit(int n, int numBits)
{
int bitPos = rand() % numBits;
unsigned int mask = ~((1 << bitPos) - 1);
if(mask & n) n &= mask;
return n - (n & (n - 1));
}[/cpp]
But this heavily favours the lower significance bits. I need something that has a much more even probability of selecting each bit.[/QUOTE]
If the bits are evenly spaced [i]on average[/i], this gives an even probability [i]on average[/i].
[cpp]int pickRandomBit(unsigned int n, unsigned int numBits, unsigned int rnd)
{
int c;
unsigned int bp = rnd % numBits;
unsigned int mask = (1 << bp);
unsigned int bit = 0;
if (n == 0) return 0;
/* Loop through the bits in a for-loop to make sure the compiler
* unrolls it. We're breaking out of it anyway. */
for (c = 0; c < 8 * sizeof(unsigned int); c++)
{
bit = mask & n;
/* If the current bit is not set, left rotate the mask bit. */
if (bit == 0)
mask = (mask << 1) | (mask >> (numBits - 1));
else break;
}
return bit;
}[/cpp]
The naive solution is the best solution if you require absolute equality. Though I wouldn't store the bits; iterate through them once to count how many bits are set, pick a random number between 0 and the amount of set bits, and iterate again to find the random bit.
[QUOTE=ECrownofFire;37294399]Is this what you mean?
[url]http://processing.org/reference/second_.html[/url][/QUOTE]
I wanted to know if there was a way to make a timer that starts when a button is pressed, and a way to reset it when a different button is pressed.
Can someone please answer this? I really try not to be spammy, but this is the third time I've asked and I've gotten no responses.
[quote]Alright, have you already built and placed GLFW in the correct folder (include and lib directories)?[/quote]
What do you mean by built?
[QUOTE=Meatpuppet;37303209]Can someone please answer this? I really try not to be spammy, but this is the third time I've asked and I've gotten no responses.
What do you mean by built?[/QUOTE]
Not trying to be rude but you really shouldnt be using C/C++ if you dont even know what this is.
One google search [url]http://www.glfw.org/release-2.7.4.html#compiling[/url]
[QUOTE=ThePuska;37303037]If the bits are evenly spaced [i]on average[/i], this gives an even probability [i]on average[/i].
[cpp]int pickRandomBit(unsigned int n, unsigned int numBits, unsigned int rnd)
{
int c;
unsigned int bp = rnd % numBits;
unsigned int mask = (1 << bp);
unsigned int bit = 0;
if (n == 0) return 0;
/* Loop through the bits in a for-loop to make sure the compiler
* unrolls it. We're breaking out of it anyway. */
for (c = 0; c < 8 * sizeof(unsigned int); c++)
{
bit = mask & n;
/* If the current bit is not set, left rotate the mask bit. */
if (bit == 0)
mask = (mask << 1) | (mask >> (numBits - 1));
else break;
}
return bit;
}[/cpp]
The naive solution is the best solution if you require absolute equality. Though I wouldn't store the bits; iterate through them once to count how many bits are set, pick a random number between 0 and the amount of set bits, and iterate again to find the random bit.[/QUOTE]
Thank you for a brilliant answer.
The bits in question are in a bitfield, and the values are more likely to be right next to each other that spaced out evenly.
As for what you said about not storing the results, I didn't think of doing it how you said.
Thanks again!
[QUOTE=Richy19;37303692]Not trying to be rude but you really shouldnt be using C/C++ if you dont even know what this is.
One google search [url]http://www.glfw.org/release-2.7.4.html#compiling[/url][/QUOTE]
I tried that already. It just says "'make' is not recognized as an internal or external command, operable program, or batch file."
[QUOTE=Meatpuppet;37307268]I tried that already. It just says "'make' is not recognized as an internal or external command, operable program, or batch file."[/QUOTE]
Make is a Unix utility. If you expect to be able to use it on Windows you have to install some form of Unix-Windows port like cygwin or msys.
You don't need be discouraging. The reason I asked is because I wanted to [I]learn[/I]. How do you think one learns? By seeing a problem that he can't solve, and finding the solution.
automerge
[QUOTE=Meatpuppet;37307311]You don't need be discouraging. The reason I asked is because I wanted to [I]learn[/I]. How do you think one learns? By seeing a problem that he can't solve, and finding the solution.
automerge[/QUOTE]
Google is an excellent tool for simple errors such as the one you posted. A general rule of internet etiquette is to search for existing solutions to the problem, and if you don't find any then make a post.
[QUOTE=calzoneman;37307369]Google is an excellent tool for simple errors such as the one you posted. A general rule of internet etiquette is to search for existing solutions to the problem, and if you don't find any then make a post.[/QUOTE]
I didn't find it; that's why I made the post
[QUOTE=lawlavex;37303184]I wanted to know if there was a way to make a timer that starts when a button is pressed, and a way to reset it when a different button is pressed.[/QUOTE]
I'd just use millis to get the start time, then use it again to compare the current time to it. The reset button would just move the start time to the current time again.
[QUOTE=Meatpuppet;37307702]I didn't find it; that's why I made the post[/QUOTE]
Comes with mingw, its called mingw32-make.
[QUOTE=Neo Kabuto;37307867]I'd just use millis to get the start time, then use it again to compare the current time to it. The reset button would just move the start time to the current time again.[/QUOTE]
Thanks, I ended up finding a nice object oriented timer that also used millis(). Another quick question, is Processing capable of doing things such as shutting down a computer?
[QUOTE=lawlavex;37308182]Another quick question, is Processing capable of doing things such as shutting down a computer?[/QUOTE]
Well, this is a tricky question. Simple answer: yes, Processing is capable of doing [i]anything[/i]. Processing is really just a library for Java. Java can do technically do anything. But there is no nice, built-in, cross-platform way to shut down a computer with Java. You can either invoke the system executable responsible for shutting down (shutdown.exe on Windows, shutdown on Linux), or you can use trickier things like JNI to call the API function responsible for shutting down. But JNI would be really awkward to get working in a Processing environment (possible, but awkward).
You could use something like this (taken from [URL="http://stackoverflow.com/questions/25637/shutting-down-a-computer-using-java"]this StackOverflow post[/URL]):
[QUOTE]public static void shutdown() throws RuntimeException, IOException {
String shutdownCommand;
String operatingSystem = System.getProperty("os.name");
if ("Linux".equals(operatingSystem) || "Mac OS X".equals(operatingSystem)) {
shutdownCommand = "shutdown -h now";
}
else if ("Windows".equals(operatingSystem)) {
shutdownCommand = "shutdown.exe -s -t 0";
}
else {
throw new RuntimeException("Unsupported operating system.");
}
Runtime.getRuntime().exec(shutdownCommand);
System.exit(0);
}[/QUOTE]
But I'm not sure whether that code works directly in Processing or whether you have to explicitly import some libraries.
Sorry, you need to Log In to post a reply to this thread.