• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=AyeGill;38249038]Trying to make GLFW work on my new desktop, but opening a window fails when given a later version of OpenGL than 2.0. I checked, and my drivers support 4.1. Offending code: [CODE]#include <GL/glfw.h> #include <stdio.h> int main() { glfwInit(); glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 ); glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE ); glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE, GL_TRUE ); printf("%i", glfwOpenWindow( 800, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW )); glfwSetWindowTitle( "OpenGL" ); while( glfwGetWindowParam( GLFW_OPENED ) ) { glfwSwapBuffers(); } glfwTerminate(); return 0; } [/CODE] I found that it also works if I comment out this line: [CODE]glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );[/CODE][/QUOTE] When I was fiddling with all that OpenGL stuff I've read somewhere that "GLFW doesn't play nice with core profiles". So I recommend you to get a library like [url=http://glew.sourceforge.net/]GLEW[/url] to get all that modern functionality
How would I be able to do cross process communication in c#. So for example I would want an application to register with the main process and then be able to send data to it and have return events.
[QUOTE=AzzyMaster;38274914]How would I be able to do cross process communication in c#. So for example I would want an application to register with the main process and then be able to send data to it and have return events.[/QUOTE] Look into named pipes. [URL=http://www.switchonthecode.com/tutorials/dotnet-35-adds-named-pipes-support]This should help a bit.[/URL]
[T]http://imgur.com/mXFTV.png[/t] This is currently what my app looks like on my phone, you can swipe left and right to reorder the formula (instead of g/g/mol=mol, mol*g/mol=g for instance. The trouble is this layout (along with being mildly confusing) looks horrible on a tablet sized screen resolution. Does anyone have any recommendations for reorganizing my UI to be more (tablet) friendly?
Trying to cross-compile Chocolate-DOOM for a handheld. Results: [quote] $ ./configure --host=mipsel-linux configure: WARNING: if you wanted to set the --build type, don't use --host. If a cross compiler is detected then cross compile mode will be used checking for mipsel-linux-gcc... mipsel-linux-gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... yes checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether mipsel-linux-gcc accepts -g... yes checking for mipsel-linux-gcc option to accept ISO C89... none needed checking for mipsel-linux-ranlib... mipsel-linux-ranlib checking for python... true ./configure: line 3124: syntax error near unexpected token `1.2.15' ./configure: line 3124: `AM_PATH_SDL(1.2.15)'[/quote] Any ideas? (Yes, I do have all o' these SDL Libraries up 'n going.) [editline]1st November 2012[/editline] Meh, I done it the ugly way around, configured it natively and then changed all the 14 makefiles to point towards mipsel-linux-gcc instead of gcc.
Hey for my Java class, our homework assignment is to make a tip calculator this is what it looks like now, it just doesn't do anything..* [IMG]http://i.imgur.com/xZTYZ.png[/IMG] I'm having trouble being able to calculate the tip, total, and total if the bill is being split amongst people and displaying these values in a JTextField in another class (resultPanel). [code] import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TipCalculator extends JFrame { private billCost bill; private tipPanel tip; private splitPanel split; private resultPanel result; private JPanel ButtonGroup; private JButton calcButton; private JButton resetButton; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JFrame TipCalculator = new JFrame(); TipCalculator.setTitle("Tip Calculator"); TipCalculator.setDefaultCloseOperation(EXIT_ON_CLOSE); TipCalculator.setLayout(new GridLayout(5, 1)); TipCalculator.pack(); // Instances of each panel JPanel bill = new billCost(); JPanel tip = new tipPanel(); JPanel split = new splitPanel(); JPanel result = new resultPanel(); // Adding Panels to JFrame TipCalculator.add(bill); TipCalculator.add(tip); TipCalculator.add(split); TipCalculator.add(result); // Calculate and reset buttons JPanel buttonGroup = new JPanel(); JButton calcButton = new JButton("Calculate"); JButton resetButton = new JButton("Reset"); buttonGroup.add(calcButton); buttonGroup.add(resetButton); TipCalculator.add(buttonGroup); TipCalculator.setVisible(true); } public TipCalculator(){ calcButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { } }); resetButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { } }); } } [/code] this is the result panel: [code] import java.awt.*; import javax.swing.*; public class resultPanel extends JPanel { public resultPanel() { super(); setBorder(BorderFactory.createTitledBorder("Result")); setLayout(new GridLayout(1, 2)); JLabel r1 = new JLabel("Tip:"); JLabel r2 = new JLabel("Total:"); JLabel r3 = new JLabel ("Tip per Person:"); JLabel r4 = new JLabel("Total per Person:"); JTextField tf1 = new JTextField(); tf1.setEditable(false); JTextField tf2 = new JTextField(); tf2.setEditable(false); JTextField tf3 = new JTextField(); tf3.setEditable(false); JTextField tf4 = new JTextField(); tf4.setEditable(false); JPanel text = new JPanel(); add(text, BorderLayout.CENTER); JPanel results = new JPanel(); add(results, BorderLayout.CENTER); text.setLayout(new GridLayout(4, 1)); text.add(r1); text.add(r2); text.add(r3); text.add(r4); results.setLayout(new GridLayout(4, 1)); results.add(tf1); results.add(tf2); results.add(tf3); results.add(tf4); } } [/code]
[QUOTE=brianosaur;38283296]Hey for my Java class, our homework assignment is to make a tip calculator this is what it looks like now, it just doesn't do anything..*[/QUOTE] Initializing components in the main method is bad code smell. Instead, since the class is already extending [I]JFrame[/I], why not do it in the constructor, and then create a new [I]TipCalculator[/I] in a new thread? [cpp] public class TipCalculator extends JFrame { public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { new TipCalculator().setVisible(true); } }); // You can also set the L&F here if you need to. } public TipCalculator() { super("Tip Calculator"); // Use this instead of setTitle(). setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(new GridLayout(5, 1)); initComponents(); // Making it a separate method for improved readability. } private void initComponents() { // If you do ">JPanel< bill" like you did, you'll be shadowing the private field bill, and you'll have no way // of accessing the initialized component later on. If this is unclear, feel free to ask me to elaborate. bill = new BillCost(); add(bill); // This adds bill to the TipCalculator frame. tip = new TipPanel(); add(tip); split = new SplitPanel(); add(split); result = new ResultPanel(); add(result); // First initialize the buttons, and then their parent component. calcButton = new JButton("Calculate"); calcButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // It's best to make a private method and call it from here so you can reuse the button's functionality // on another component in the future, if you need to. // calcButtonActionPerformed(); } }); resetButton = new JButton("Reset"); resetButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // resetButtonActionPerformed(); } }); buttonGroup = new JPanel(); // If you need a button group, why not use JButtonGroup? buttonGroup.add(calcButton); buttonGroup.add(resetButton); add(buttonGroup); } // I like to declare components at the end, again for better readability. I also like to sort them alphabetically, // by class name, but you don't have to by any means. private BillCost bill; // ALWAYS name your classes using CamelCase; they're not methods (billCost)! private TipPanel tip; private SplitPanel split; private ResultPanel result; private JPanel buttonGroup; // Don't start field names with a capital letter (ButtonGroup); they're not classes! private JButton calcButton; private JButton resetButton; } [/cpp] As you can see, doing it in the constructor makes for much more readable code (plus you don't have to prefix everything with [I]TipCalculator[/I]).
Okay, I see. Your code is so much easier to read! Thanks! A couple things I don't understand though: 1. What does that code in the main method do? We never learned that 2. for the initComponents method, since it's has a void type, how would I be able to set the value in the JTextField in the ResultPanel after the "calculate" button has been clicked?
[QUOTE=brianosaur;38287519] 1. What does that code in the main method do? We never learned that [/QUOTE] That code tells it to create a new TipCalculator JFrame and display it. [QUOTE=brianosaur;38287519] 2. for the initComponents method, since it's has a void type, how would I be able to set the value in the JTextField in the ResultPanel after the "calculate" button has been clicked?[/QUOTE] In the event listener for the button, have it calculate the tip and then set it in the resultPanel like you normally would.
[QUOTE=brianosaur;38287519]1. What does that code in the main method do? We never learned that[/QUOTE] I assume you're referring to [I]SwingUtilities.invokeLater()[/I]. That method ensures that the frame is created and displayed in the event dispatch thread since [URL=http://docs.oracle.com/javase/6/docs/api/javax/swing/package-summary.html#threading]Swing isn't thread-safe[/URL]. Long story short, you may run into problems if you don't display GUI components in that thread, so it's always best to have that in your code. [QUOTE=brianosaur;38287519]2. for the initComponents method, since it's has a void type, how would I be able to set the value in the JTextField in the ResultPanel after the "calculate" button has been clicked?[/QUOTE] From my previous code: [cpp] calcButton = new JButton("Calculate"); calcButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // Specify what you want the button to do when clicked here. result.tf1.setText("your text goes here"); } }); [/cpp] In order to be able to do [I]result.tf1[/I], however, you will have to make [I]tf1[/I] a field in [I]ResultPanel[/I] (no-modifier rather than private); otherwise, [I]tf1[/I] won't be visible from within your [I]TipCalculator[/I] class. For example: [cpp] public class ResultPanel extends JPanel { /* Constructor */ public ResultPanel() { // ... } /* Component Declarations */ JTextField tf1; JTextField tf2; JTextField tf3; JTextField tf4; // other components... } [/cpp] You could also accomplish this by adding making a [I]setTextFieldText(int textFieldIndex, String text)[/I] method in [I]ResultPanel[/I], which would allow you to keep the [I]JTextField[/I]s private.
So I signed up for .edu Dreamspark, is VS 2010 preferred over VS 2012? I'm going to be using it for C# and XNA. Does Team Foundation Server support my friend and I both editing code at the same time, or should I just use AnkhSVN and some online repo site?
I have been working on dual contouring but I cant figure out why its not rendering correctly What it does look like: [t]http://puu.sh/1lDVf[/t] What it should look like: [t]http://puu.sh/1lDWR[/t] My dual contouring code: [CODE]class DualContour: def __init__(self, noise=None): self.isovalue = 0.0 self.noise = noise #Cardinal directions self.dirs = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] #Vertices of cube self.cube_verts = [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]] #Edges of cube self.cube_edges = [[0, 1], [0, 2], [0, 1], [0, 4], [0, 2], [0, 4], [2, 3], [1, 3], [4, 5], [1, 5], [4, 6], [2, 6], [4, 5], [4, 6], [2, 3], [2, 6], [1, 3], [1, 5], [6, 7], [5, 7], [6, 7], [3, 7], [5, 7], [3, 7]] self.center = np.array([16, 16, 16]) self.radius = 10 def estimate_hermite(self, noise, v0, v1): def brentf(t): ni = (1. - t) * v0 + t * v1 ret = noise.getDensity(Point3(ni[0], ni[1], ni[2])) return ret #root finding equation t0 = opt.brentq(brentf, 0, 1) #find exactly where the sign changes x0 = (1. - t0) * v0 + t0 * v1 #get derivative of x0 den = noise.getDensity(Point3(x0[0], x0[1], x0[2]), True)[1] return (x0, den) def generateMesh(self, terrain, size, lod): dc_verts = [] vindex = {} noise = self.noise for x, y, z in itertools.product(xrange(0, size - 1), xrange(0, size - 1), xrange(0, size - 1)): o = np.array([x, y, z]) cube_signs = [] #find edges that have a sign change for v in self.cube_verts: ni = o + v sign = noise.getDensity(Point3(ni[0], ni[1], ni[2])) if sign > self.isovalue: cube_signs.append(True) else: cube_signs.append(False) #if all are True or all are False skip this run of the loop, there is no sign change if all(cube_signs) or not any(cube_signs): continue #Estimate hermite data h_data = [] for e in self.cube_edges: #if sign change if cube_signs[e[0]] != cube_signs[e[1]]: #input f, df, and 2 verts out comes p and n h_data.append(self.estimate_hermite(noise, o + self.cube_verts[e[0]], o + self.cube_verts[e[1]])) #Solve qef to get vertex A = [] b = [] for p, n in h_data: A.append(n) b.append(np.dot(p, n)) v, residue, rank, s = la.lstsq(A, b) #Throw out failed solutions if la.norm(v - o) > 2: continue #Emit one vertex per every cube that crosses vindex[tuple(o)] = len(dc_verts) dc_verts.append(v) #Construct faces dc_faces = [] for x, y, z in itertools.product(xrange(0, size - 1), xrange(0, size - 1), xrange(0, size - 1)): if not (x, y, z) in vindex: continue #Emit one face per each edge that crosses o = np.array([x, y, z]) for i in range(3): for j in range(i): if tuple(o + self.dirs[i]) in vindex and tuple(o + self.dirs[j]) in vindex and tuple(o + self.dirs[i] + self.dirs[j]) in vindex: dc_faces.append( [vindex[tuple(o)], vindex[tuple(o+self.dirs[i])], vindex[tuple(o+self.dirs[j])]] ) dc_faces.append( [vindex[tuple(o+self.dirs[i]+self.dirs[j])], vindex[tuple(o+self.dirs[j])], vindex[tuple(o+self.dirs[i])]] ) dc_triangles = [] for face in dc_faces: v1 = dc_verts[face[0]] v2 = dc_verts[face[1]] v3 = dc_verts[face[2]] dc_triangles.append(((v1[0], v1[1], v1[2]), (v2[0], v2[1], v2[2]), (v3[0], v3[1], v3[2]))) return dc_triangles[/CODE] getDensity function: [CODE] def getDensity(self, cords, getDer=False): #return 1.0 x, y, z = cords[0], cords[1], cords[2] den, der = raw_noise_3d(x / 15.0, y / 15.0, z / 15.0) if getDer: return den, der else: return den[/CODE] raw_noise_3d: [url]https://gist.github.com/4003749[/url]
[QUOTE=Hypershadsy;38290482]So I signed up for .edu Dreamspark, is VS 2010 preferred over VS 2012? I'm going to be using it for C# and XNA. Does Team Foundation Server support my friend and I both editing code at the same time, or should I just use AnkhSVN and some online repo site?[/QUOTE] XNA isn't supported for VS2012. There are workarounds but from what I know you need VS2010 installed as well. So I'd recommend just going with 2010 if you're going to do XNA. With that said, 2012 is way better in my opinion but I have both installed. Team Foundation Server is something you'll have to purchase (afaik) so I recommend the latter.
I've heard C# is like Java. I learning a bit of Java from comp sci, but would be cool to know C# as well. I thought I'd ask here first so I can get some nice answers instead of looking at Google and find out I'm learning some outdated shit.
[QUOTE=jung3o;38293690]I've heard C# is like Java. I learning a bit of Java from comp sci, but would be cool to know C# as well. I thought I'd ask here first so I can get some nice answers instead of looking at Google and find out I'm learning some outdated shit.[/QUOTE] Syntax-wise, C# has a lot of cool new language features that Java lacks, like properties, built-in events and delegates, lambdas, etc. As of recently (with the .NET 4.5 release) there's also built-in support for [url=http://blogs.msdn.com/b/dotnet/archive/2012/04/03/async-in-4-5-worth-the-await.aspx]asynchronous programming with the "async" and "await" keywords.[/url] The BCL isn't as large as the JCL and there's a bit of Windows-specific code in it, but for the most part it's also cross-platform with [url=http://mono-project.com/Main_Page]Mono[/url]. There wsa a more in-depth discussion about .NET's cross platform-ness in [url=http://facepunch.com/showthread.php?t=1221898&page=2]this thread[/url]. You can also package C# binaries to look like native binaries/apps on Linux/OSX in the same way you can for Java.
I'm making a 2D mining/platformer game, and I need help with collision detection with the player. Here's my collision code (in the Player class.) [code] public void Update(WorldManager world) // Credit to "someone972" of allegro.cc forums for the skeleton. { Velocity = new Vector2(0, Velocity.Y + 1); if (Keyboard.GetState().IsKeyDown(Keys.A)) { Velocity = Velocity + new Vector2(-2, 0); } if (Keyboard.GetState().IsKeyDown(Keys.D)) { Velocity = Velocity + new Vector2(2, 0); } foreach (Tile tile in world.Ground) { Rectangle box = new Rectangle((int)Position.X + 2, (int)Position.Y, 16, 20); // Make us skinnier so we fit in 1x1 holes. Rectangle tilebox = new Rectangle((int)tile.Position.X, (int)tile.Position.Y, 20, 20); if (Vector2.Distance(Position, tile.Position) <= 40 && box.Y + box.Height >= tilebox.Y && box.Y <= tilebox.Y + tilebox.Height && box.X + box.Width >= tilebox.X && box.X <= tilebox.X + tilebox.Width) { tile.IsColliding = true; Collision collision = Collision.Bottom; int overlap = Math.Abs((box.Y + box.Height) - tilebox.Y); if (Math.Abs(box.Y - (tilebox.Y + tilebox.Height)) < overlap) { overlap = Math.Abs(box.Y - (tilebox.Y + tilebox.Height)); collision = Collision.Top; } if (Math.Abs((box.X + box.Width) - tilebox.X) < overlap) { overlap = Math.Abs((box.X + box.Width) - tilebox.X); collision = Collision.Right; } if (Math.Abs(box.X - (tilebox.X + tilebox.Width)) < overlap) { overlap = Math.Abs(box.X - (tilebox.X + tilebox.Width)); collision = Collision.Left; } if (collision == Collision.Bottom) { Velocity = new Vector2(Velocity.X, 0); Position = new Vector2(Position.X, (float)Math.Floor((decimal)Position.Y / 20) * 20); } else if (collision == Collision.Top) { // We can't jump yet, so there is no need for upwards collisions. } else if (collision == Collision.Right) { Velocity = new Vector2(0, Velocity.Y); Position = new Vector2((float)Math.Floor((decimal)Position.X / 20) * 20, Position.Y); } else if (collision == Collision.Left) { Velocity = new Vector2(0, Velocity.Y); Position = new Vector2((float)Math.Ceiling((decimal)Position.X / 20) * 20, Position.Y); } } else { tile.IsColliding = false; } } Position = Position + Velocity; } [/code] My problem is that when I have a side collision (left or right, hitting a wall etc) my player shakes like hell over the distance of about one or two pixels. My guess is that it has something to do with me making the player's bounding box skinnier than the actual player. I've tried almost everything and I can't seem to fix it. Thank you very much for any help. [editline]3rd November 2012[/editline] Also, here's my test build so you can see what the actual problem is. [url]http://filesmelt.com/dl/Payload_test.zip[/url][code] Q = Toggle debug display A/D = Move Left click = Add tiles Right click = Remove tiles [/code]
I need help with implementing random terrain generation algorithms into my code. My problem is that most of the algorithms I find are either in pseudocode or are just snippets. I have no idea how to implement that into an actual program. I'm using C++ and DirectX.
[QUOTE=Meatpuppet;38296268]I need help with implementing random terrain generation algorithms into my code. My problem is that most of the algorithms I find are either in pseudocode or are just snippets. I have no idea how to implement that into an actual program. I'm using C++ and DirectX.[/QUOTE] This topic has some useful links and info: [URL="http://facepunch.com/showthread.php?t=1222954"]http://facepunch.com/showthread.php?t=1222954[/URL]
[QUOTE=Meatpuppet;38296268]I need help with implementing random terrain generation algorithms into my code. My problem is that most of the algorithms I find are either in pseudocode or are just snippets. I have no idea how to implement that into an actual program. I'm using C++ and DirectX.[/QUOTE] They're pseudocode because terrain generation is such a broad subject. There are common solutions that are usually applied at some point, but often the generation algorithm is completely unique to the application. Are you using 3D or 2D? Are heightmaps relevant? Are biomes relevant? Do you intend to do simulation, e.g. for erosion/wind/rainfall? Do you need real 3D, meaning mere heightmaps won't do (for "alcoves" and such)? Are there additional requirements, e.g. every (non-blocking) point on the map is accessible from every other point? Or that a histogram of the map's heights, or terrain types, meets some specifications (not too much water, not too flat, or somesuch)? [editline]3rd November 2012[/editline] Your problem is so general that you should expect to get general answers.
[QUOTE=Walker;38298285]This topic has some useful links and info: [URL="http://facepunch.com/showthread.php?t=1222954"]http://facepunch.com/showthread.php?t=1222954[/URL][/QUOTE] I like how you responded to him with his own thread, lol.
Is it me or is the step from command line C++ to Win32 C++ a huge bitch. So much lines of code to do nothing (well that you don't immediately see). Anyone have tutorial suggestions for the most basic Win32 HelloWorld program?
[QUOTE=Number-41;38298976]Is it me or is the step from command line C++ to Win32 C++ a huge bitch. So much lines of code to do nothing (well that you don't immediately see). Anyone have tutorial suggestions for the most basic Win32 HelloWorld program?[/QUOTE] Win32, as in using forms ? [code] int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { MessageBoxA(NULL, "HEY GUYS", "WASSUP", MB_OK); } [/code] For Win32 stuff, the entry point is not main() but WinMain() [strikethrough]If your goal is to make a window, Visual Studio's base code is pretty good:[/strikethrough] Scratch that, there's too much bullshit. Here's some cleaner code for Window creation [code] #include <Windows.h> HWND GetWindowHandle(int, int, WNDPROC); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); HWND GetWindowHandle(int width, int height, char* windowName, WNDPROC wndProc) { WNDCLASSEX wc; int posX, posY; Instance = (HINSTANCE)GetModuleHandle(NULL); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = wndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = Instance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hIconSm = wc.hIcon; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = windowName; wc.cbSize = sizeof(WNDCLASSEX); RegisterClassEx(&wc); DWORD WinStyle; WinStyle = WS_CAPTION; posX = (GetSystemMetrics(SM_CXSCREEN) - width) / 2; posY = (GetSystemMetrics(SM_CYSCREEN) - height) / 2; return CreateWindowEx(WS_EX_APPWINDOW, windowName, windowName, WinStyle, posX, posY, width, height, NULL, NULL, Instance, NULL); } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: { PostQuitMessage(0); return 0; } case WM_CLOSE: { PostQuitMessage(0); return 0; } default: { return DefWindowProc(hwnd, umsg, wparam, lparam); } } } [/code]
And is there some comprehensive tutorial that explains each of these components? [URL="http://www.cprogramming.com/tutorial/opengl_first_windows_app.html"]This one[/URL] is a bit brief...
[QUOTE=Number-41;38299835]And is there some comprehensive tutorial that explains each of these components? [URL="http://www.cprogramming.com/tutorial/opengl_first_windows_app.html"]This one[/URL] is a bit brief...[/QUOTE] I'll try to explain it, in the order in which it appear. (I also noticed that I left a few things from my code, where this function actually belongs to a Window class, so a few things are different, I'll edit it later) [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms633559(v=vs.85).aspx"]WinMain[/url] is the entry point for Win32 applications. You don't need to give a shit about what HINSTANCEs are for now, because Windows handles them. An [url="http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#hwnd"]HWND[/url] is a Handle to a WiNDow. The first function, GetWindowHandle() creates everything that you need to get a Window. The first thing it fills is a [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms633577(v=vs.85).aspx"]WNDCLASSEX[/url], a structure which defines how your window behaves, looks, etc. [code] wc.style is how your window behaves. A list of all the values you can input here is available on [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ff729176(v=vs.85).aspx"]MSDN, here.[/url]Just separate them with a Bitwise OR, and you'll be able to use multiple of them. In this example, CS_HREDRAW means "redraw the entire window if its width changes", CS_VREDRAW means "redraw the entire window if its height changes", and CS_OWNDC means "allocate a [url="http://msdn.microsoft.com/fr-fr/library/windows/desktop/dd183553(v=vs.85).aspx"]device context[/url] for this particular window wc.lpfnWndProc is a callback/pointer to a [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms633573(v=vs.85).aspx"]WindowProc[/url]. It represents what function your window will call every time it receives a message from Windows. wc.cbClsExtra and wc.cbWndExtra are the bytes you want to allocate in extra for your window. Never really understood what it was used for, but I'm sure it has an application. wc.hInstance is the HINSTANCE this window will be created for. We just get the current application handle (NULL) and cast it to an HINSTANCE. You can also create HWNDs for other instances, but that's not the goal here. wc.hIcon is the icon this window will use. Here, we load an icon from Windows's base icons (IDI_WINLOGO), therefore, the first parameter NEEDS to be NULL. If you want to load an icon from another application (i.e. not windows's base icons), you need a handle to this application (see [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms648072(v=vs.85).aspx"]the LoadIcon() MSDN page for more details[/url] wc.hIconSm is the same thing, but for the small 32*32 icons. We set it to be the same as the application's icon. wc.cursor is the cursor we use in this application. We use the [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms648391(v=vs.85).aspx"]LoadCursor()[/url] function, usage is the same as LoadIcon(). wc.hbrBackground is the background of this window. In our case, the window will be black. It's a handle to a brush. Therefore, in our case, we get a BLACK_BRUSH and cast it to a HBRUSH. Some HBRUSH are already available, refer to the MSDN on WNDCLASSEX. wc.lpszMenuName is a bit more interesting. It's how you define the top menus in your application. Here, it's set to NULL, so we won't have one. Creating one is a bit trickier, and requires using the [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms648029(v=vs.85).aspx"]MAKEINTRESOURCE[/url] macro. Never used it, so I couldn't tell you. wc.lpszClassName is the name of the window when it is registered. It's some Win32 magic, so I don't really know what the fuck it is doing behind the scenes. That said, in this case, the ClassName is the same as the window caption. wc.cbSize is the size of this WNDCLASSEX structure. always set it to sizeof(WNDCLASSEX). (Why it isn't already done, I don't know) [/code] So, now that we've got our window description, let's register it so that Windows can send messages to it and receive messages from it. It's simply a matter of calling RegisterClassEx (notice the Ex: We're creating a wndclassEx, so we use the corresponding method. I don't know if Win32 uses some #define trickery to define RegisterClass(), so better safe than sorry.) and passing a reference to the window description. Now that our window is registered, we need to create it (registering is DEFINITELY NOT creating it as a form.) so that you can see it. WinStyle is a DWORD, which I use because it's a bit more practical if you want to use the Window properties elsewhere (actually, in this case, it's a leftover of my Window class which I didn't really bother to change for this example.) DEVMODE is also a leftover from my code (however, if you want to have a fullscreen window, it is needed). Will remove it. posX and posY are calculated so that the window is created right at the center of the screen. Finally, we return [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspx"]CreateWindowEx()[/url], which returns a handle to the newly created window On to WndProc now. WndProc is the message handler for this window, which we passed as a parameter when creating it (wc.lpfnWndProc). In our case, it reads the message (which is represented as a UINT) and does a simple switch to know what to do. If this message is a WM_DESTROY message or a WM_QUIT message, we exit correcly by calling PostQuitMessage(0). 0 is the exit code. No error, exit code = 0. Else, it calls the default message handler (which Windows defines).
I'm trying to compile my C program using GLFW but I get errors about the functions reference. I did setup correctly and I don't know what's happening. Here's the picture. [img]http://img706.imageshack.us/img706/6726/errorsgq.jpg[/img] Grateful for help me.
[QUOTE=Cesar Augusto;38300759]I'm trying to compile my C program using GLFW but I get errors about the functions reference. I did setup correctly and I don't know what's happening. Here's the picture. [t]http://img706.imageshack.us/img706/6726/errorsgq.jpg[/t] Grateful to help me.[/QUOTE] Without any code, it's kind of hard to know, but I'd say you forgot to #include GLFW.
[QUOTE=PiXeN;38300782]Without any code, it's kind of hard to know, but I'd say you forgot to #include GLFW.[/QUOTE] [cpp] #include <GL/glfw.h> #include <stdlib.h> int main(int argc, char *argv[]) { int running = GL_TRUE; // Initialize GLFW if( !glfwInit() ) { exit( EXIT_FAILURE ); } // Open an OpenGL window if( !glfwOpenWindow( 300,300, 0,0,0,0,0,0, GLFW_WINDOW ) ) { glfwTerminate(); exit( EXIT_FAILURE ); } // Main loop while( running ) { // OpenGL rendering goes here... glClear( GL_COLOR_BUFFER_BIT ); // Swap front and back rendering buffers glfwSwapBuffers(); // Check if ESC key was pressed or window was closed running = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED ); } // Close window and terminate GLFW glfwTerminate(); // Exit program exit( EXIT_SUCCESS ); } [/cpp] I'm just trying the code of the manual ;)
It's a linker error. You're not linking to glfw libraries. You'd append the linked libraries to your command line, or use a makefile
[QUOTE=ThePuska;38300891]It's a linker error. You're not linking to glfw libraries. You'd append the linked libraries to your command line, or use a makefile[/QUOTE] I use mingw: gcc -o teste teste.c -lglfw -lopengl32. I did that as site recomendation.
I'm testing out Visual Studio 2012, for C# specifically. Can someone tell me if it's possible to have some references and other files in the project dependent on your solution platform? I need to reference different DLLs on x86 and x64, and copy different DLLs to the output folder depending on the platform. It'd be nice to automate this.
Sorry, you need to Log In to post a reply to this thread.