• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=dajoh;35536651]Curl isn't compiled right, it's linked to _inet_pton as if it used the cdecl calling convention, but inet_pton is exported by ws2_32.dll with the stdcall convention.[/QUOTE] After a quick google search to figure out what the fuck that actually is, that helps a ton. Thanks, it should probably work now. Edit: Nah it's still overly complicated. At this point it might be easier to just use something like SFML or boost. Oh well, at least I tried. When i'm finished with windows support i'll go back and learn more about this particular problem.
One of my first projects in Java, though I have alot of experience using Actionscript 3, Im writing a simple rouge-like using the libjcsi library. What is the best way to make a game loop, ive seen lots of different methods, atm im justing a while loop which is not desireable. Heres my code [code]// body.java package engine; import net.slashie.libjcsi.wswing.WSwingConsoleInterface; import net.slashie.libjcsi.CharKey; import net.slashie.libjcsi.ConsoleSystemInterface; import net.slashie.libjcsi.CSIColor; import java.util.Properties; import java.io.*; import engine.character; public class body { public static void main(String[] args){ Properties text = new Properties(); text.setProperty("fontSize","12"); text.setProperty("font", "courier"); ConsoleSystemInterface csi = null; try{ csi = new WSwingConsoleInterface("Rougelike", text); } catch (ExceptionInInitializerError eiie) { System.out.println("Rouglike has encountered an unexpected error"); eiie.printStackTrace(); System.exit(-1); } final int u = 80; // map bound x. final int v = 11; // map bound y. char [][] map = new char[v][u]; // array containing display characters. char [][] mapCol = new char[v][u]; // duplicate array containing colors. String zone = "Lumbridge"; character player = new character(); // #108 - retrieve values from text file. map = readFromFile(zone,u,v); mapCol = readFromFile(zone + "_colour",u,v); // add player [@] to map array. map[player.y][player.x] = '@'; mapCol[player.y][player.x] = '4'; draw(v,u,map,mapCol,zone,player.health,player.exp,player.level,csi); /// Game loop /// boolean stop = false; while(!stop){ CharKey dir = csi.inkey(); if(dir.isUpArrow() && player.y-1>0){ csi.cls(); // clear console screen. map = refreshMap(map, zone, u, v); mapCol = refreshMapCol(mapCol, zone, u, v); player.y-=1; // move player on (inverted) y axis. map[player.y][player.x] = '@'; mapCol[player.y][player.x] = '4'; draw(v,u,map,mapCol,zone,player.health,player.exp,player.level,csi); csi.refresh(); // refresh console. } else if (dir.isDownArrow() && player.y+2<v){ csi.cls(); map = refreshMap(map, zone, u, v); mapCol = refreshMapCol(mapCol, zone, u, v); player.y+=1; map[player.y][player.x] = '@'; mapCol[player.y][player.x] = '4'; draw(v,u,map,mapCol,zone,player.health,player.exp,player.level,csi); csi.refresh(); } else if (dir.isRightArrow() && player.x+2<u){ csi.cls(); map = refreshMap(map, zone, u, v); mapCol = refreshMapCol(mapCol, zone, u, v); player.x+=1; map[player.y][player.x] = '@'; mapCol[player.y][player.x] = '4'; draw(v,u,map,mapCol,zone,player.health,player.exp,player.level,csi); csi.refresh(); } else if (dir.isLeftArrow() && player.x-1>0){ csi.cls(); map = refreshMap(map, zone, u, v); mapCol = refreshMapCol(mapCol, zone, u, v); player.x-=1; map[player.y][player.x] = '@'; mapCol[player.y][player.x] = '4'; draw(v,u,map,mapCol,zone,player.health,player.exp,player.level,csi); csi.refresh(); } } } public static char[][] readFromFile(String file, int u, int v){ char [][] ret = new char[v][u]; int i=0; try{ String fileName = new String ("C:/Users/Tom/Java/dungeon/level/" + file + ".txt"); FileInputStream fstream = new FileInputStream(fileName); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; // array [x][y] = text file [x][y]. while ((strLine = br.readLine()) != null) { for(int x=0; x<strLine.length(); x++){ char [] lineArr = strLine.toCharArray(); ret[i][x] = lineArr[x]; } i++; } in.close(); } catch (Exception e){ System.err.println("Error: " + e.getMessage()); } return ret; } public static void draw(int v, int u, char map[][], char mapCol[][], String zone, int health, double xp,int level, ConsoleSystemInterface csi){ csi.print(0,0," " + zone, CSIColor.WHITE); int colour = 15; for(int x=0; x<u; x++){ for(int y=0; y<v; y++){ colour = Integer.parseInt(Character.toString(mapCol[y][x]),16); // set color to value (hex) defined in color file. csi.print(x, y+1, Character.toString(map[y][x]), colour); // print map to console } } csi.print(1,v+1,"health : " + health, CSIColor.WHITE); csi.print(15,v+1,"exp : " + xp + '%', CSIColor.WHITE); csi.print(28,v+1,"level : " + level, CSIColor.WHITE); } public static char[][] refreshMap(char map[][], String zone, int u, int v){ map = readFromFile(zone,u,v); return map; } public static char[][] refreshMapCol(char mapCol[][], String zone, int u, int v){ mapCol = readFromFile(zone + "_colour",u,v); return mapCol; } } // character.java package engine; import java.text.DecimalFormat; public class character { public int x = 10; public int y = 3; public int health = 100; public int level = 1; private double cap = 256.0; // experience cap. public double xp = 0; public double exp = round(100 * ((xp!=0) ? xp/cap:0)); public static void main(String[] args) { } public void experience(double dt){ if (xp+dt>=cap){level+=1; xp=0;} else {xp+=dt;}; exp = round(100 * ((xp!=0) ? xp/cap:0)); } double round(double d) { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(d)); } [/code]
[QUOTE=ROBO_DONUT;35535273]I think you've got your coordinate systems mixed up. 'eye-space' or 'view-space' is just like world-space, except that the origin is centered at the viewer, looking down the negative-Z axis. The transformation between view-space and world-space is just a simple translation and rotation. There is no scale, skew, or perspective involved. Radius should be the same in both view-space and world-space. You aren't trying to work in clip space (pre-perspective-division) or NDC/screen (post-perspective-division), are you? If you're working post-perspective-division, things get a little more complicated due to perspective distortion. Have this nifty leftover graphic I made for a post that I never wrote for a blog that I never made: You can try to correct for it with some trig, or you can just render an icosphere.[/QUOTE] The entirety of the renderers work is currently done post perspective division (ah, its called screenspace), so the radius needed to be scaled by depth Its fixed now thought, and seems to be working quite nicely. Thanks for the explanation, there's a lot of random terminology involved
What GUI framework should I use to start learning? I can do some C++ console things but I want a fancy screen... I downloaded QT but the tutorials on the site remind me of W3C School, with lots of comments that correct the tutorials (so doesn't seem like a good spot to learn). On top of that, it looks corporate/proprietary as fuck so I doubt it's something that the industry uses in the same way as it uses C++ (I might be wrong here)
[QUOTE=Number-41;35540114]What GUI framework should I use to start learning? I can do some C++ console things but I want a fancy screen... I downloaded QT but the tutorials on the site remind me of W3C School, with lots of comments that correct the tutorials (so doesn't seem like a good spot to learn). On top of that, it looks corporate/proprietary as fuck so I doubt it's something that the industry uses in the same way as it uses C++ (I might be wrong here)[/QUOTE] SFML is a good library, and an alternative to that is SDL
Just got a new college Assignment, have to make a chat client, using threads and all that sort of stuff. It's for our OS module. Anybody have any advice on it? A lot of work to do since its due the day after our big C++ project
hi i'm trying make something cool in c. can't tell you further.. early stage.. my c code spams because of the while loop but i really need it.. [code] while(1){ number=atoi(buf); if(number==1){printf("1"); number=0;} else if(number==2){printf("2"); number=0;} else if(number==3){printf("3"); number=0;} else if(number==4){printf("4"); number=0;} else if(number==5){printf("5"); number=0;} else if(number==6){printf("6"); number=0;} else{} } [/code] anyone knows how to stop this madness? edit: lol, how dumb am I? the answer is in the code, :v: nvm i guess.
Working on an assignment for my Java class, but it's not working particularly well [php]package assg3.music; import assg3.musicartistscollection.MusicArtistsCollection; import static javax.swing.JOptionPane.*; import static java.lang.System.out; public class MusicArtistsApp { public static void main (String [] args) { String collectorName = showInputDialog("Enter your name"); String artistsInfo = "ZZ TOP,14,4/DAVID BOWIE,27,16/ROLLING STONES," + "50,21/ALPHAVILLE,10,1/BEATLES,40,37/CELINE DION,9,7/ALAN PARSONS," + "14,4/PINK FLOYD,20,6/CURE,27,12/ABBA,14,4/KILLERS,4,4/COLDPLAY,6," + "5/STEELY DAN,9,8/SOUNDS,3,2/"; MusicArtistsCollection myFavourites = new MusicArtistsCollection(collectorName, artistsInfo); } }[/php] [php]package assg3.musicartistscollection; public class MusicArtistsCollection { private String collectorName = ""; private String[] artistsNames = new String[50]; private int[] numAlbums = new int[50]; private int[] numGoldAlbums = new int[50]; private int counter = 0; public MusicArtistsCollection() {} public MusicArtistsCollection(String collectorName, String artistsInfo) { this.collectorName = collectorName; artistsInfoAnalyser(artistsInfo); } //Custom Methods private void artistsInfoAnalyser(String artistsInfo) { for (int i = 0; i < artistsInfo.length();) { artistsNames[counter] = artistsInfo.substring(i, artistsInfo.indexOf(",", i)); i = artistsInfo.indexOf(",", i) + 1; numAlbums[counter] = Integer.parseInt(artistsInfo.substring(i, artistsInfo.indexOf(",", i))); i = artistsInfo.indexOf(",", i) + 1; numGoldAlbums[counter] = Integer.parseInt(artistsInfo.substring(i, artistsInfo.indexOf("/", i))); counter++; i++; } } }[/php] Running the app gives this error [quote]Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -203 at java.lang.String.substring(String.java:1958) at assg3.musicartistscollection.MusicArtistsCollection.artistsInfoAnalyser(MusicArtistsCollection.java:62) at assg3.musicartistscollection.MusicArtistsCollection.<init>(MusicArtistsCollection.java:16) at assg3.music.MusicArtistsApp.main(MusicArtistsApp.java:17)[/quote] So something's wrong with the analyser method there, but I'm not sure what. Help? :v: That method is supposed to separate the different fields in the string that's sent in into arrays, btw. Also I cut out some lines of the code so the line numbers in the error message won't match up. I'll fix that later, sorry. [editline]fixed[/editline] Turns out it was the i++ causing the problem, doing this fixed it [php]i = artistsInfo.indexOf("/", i) + 1;[/php]
[QUOTE=Bazkip;35544322]Working on an assignment for my Java class, but it's not working particularly well -code snip- Running the app gives this error So something's wrong with the analyser method there, but I'm not sure what. Help? :v: That method is supposed to separate the different fields in the string that's sent in into arrays, btw. Also I cut out some lines of the code so the line numbers in the error message won't match up. I'll fix that later, sorry.[/QUOTE] I may be wrong but won't [php] artistsInfo.indexOf(",", i); [/php] return a negative number if it finds nothing? I.E. You need to check if indexOf is negative (you are at the last substring) before you call substring or it will spit out an error (you cant start at a negative index within a string)
I'm trying to load an image using [b]DevIL[/b], but it fails every time. Does anyone know why it would? Here's the loading-code. [CODE]// Load an image if (ilLoadImage((const ILstring)"logo.png") == false) { fprintf(stderr, "Failed to load image.\n"); return 0; }[/CODE]
[QUOTE=Mordi;35545196]I'm trying to load an image using [b]DevIL[/b], but it fails every time. Does anyone know why it would? Here's the loading-code. [CODE]// Load an image if (ilLoadImage((const ILstring)"logo.png") == false) { fprintf(stderr, "Failed to load image.\n"); return 0; }[/CODE][/QUOTE] I'm pretty sure you've already called ilInit() - you'd be segfaulting on that line if you hadn't. So that's not an issue. Have you called ilGenImages and ilBindImage first? If not, that's your problem. Otherwise, it's probably unable to find the image - most likely due to a working directory issue. You can check this by putting in the full path of the image, until you work out what the filename should be or the best way to run the program to avoid working directory path issues. eg for reference here is how I use DevIL [cpp] ilGenImages(1, &ImageHandle_); ilBindImage(ImageHandle_); bool ret = ilLoadImage(Filename_.c_str()); if(ilGetError() == IL_COULD_NOT_OPEN_FILE) { printf("\nError loading texture file \"%s\"\n\n", Filename_.c_str()); ilDeleteImages(1, &ImageHandle_); ImageHandle_ = 0; return false; } else if(ret == false) { // Some other error occurred. We could poll the whole IL stack, but // I can't be assed writing code for all that. ilDeleteImages(1, &ImageHandle_); ImageHandle_ = 0; return false; } // Ensure image is in RGBA format. ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); return true; [/cpp]
Can someone help me with the cube positioning? I have this for the vertex positions: [cpp]g_vertex_buffer_data[0] = -0.5f; g_vertex_buffer_data[1] = 0.5f; g_vertex_buffer_data[2] = -0.5f; g_vertex_buffer_data[3] = 0.5f; g_vertex_buffer_data[4] = 0.5f; g_vertex_buffer_data[5] = -0.5f; g_vertex_buffer_data[6] = 0.5f; g_vertex_buffer_data[7] = -0.5f; g_vertex_buffer_data[8] = -0.5f; g_vertex_buffer_data[9] = -0.5f; g_vertex_buffer_data[10] = -0.5f; g_vertex_buffer_data[11] = -0.5f; g_vertex_buffer_data[12] = -0.5f; g_vertex_buffer_data[13] = 0.5f; g_vertex_buffer_data[14] = 0.5f; g_vertex_buffer_data[15] = 0.5f; g_vertex_buffer_data[16] = 0.5f; g_vertex_buffer_data[17] = 0.5f; g_vertex_buffer_data[18] = 0.5f; g_vertex_buffer_data[19] = -0.5f; g_vertex_buffer_data[20] = 0.5f; g_vertex_buffer_data[21] = -0.5f; g_vertex_buffer_data[22] = -0.5f; g_vertex_buffer_data[23] = 0.5f; [/cpp] this for the UV: [cpp] for(int i = 0; i < 6; i++) { int ii = i * 8; uv_data[0 + ii] = 0.0f; uv_data[1 + ii] = 0.0f; uv_data[2 + ii] = 1.0f; uv_data[3 + ii] = 0.0f; uv_data[4 + ii] = 1.0f; uv_data[5 + ii] = 1.0f; uv_data[6 + ii] = 1.0f; uv_data[7 + ii] = 1.0f; } [/cpp] And this for the indicies: [cpp] int i = 0; i = 1; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 2; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 0; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 0; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 2; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 3; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 0; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 3; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 4; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 4; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 3; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 7; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 4; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 7; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 5; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 5; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 7; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 6; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 5; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 6; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 2; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 1; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 5; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 2; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 4; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 5; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 0; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 0; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 5; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 1; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 6; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 7; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 3; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 2; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 6; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 ); i = 3; indices.push_back( i*3 ); indices.push_back( i*3 + 1 ); indices.push_back( i*3 + 2 );[/cpp] Yet this is what gets drawn: [img]http://i.imgur.com/G4fHm.png[/img]
[QUOTE=mutated;35535174]Explain this. So I have a generic method, like getStat(String attackpower) and it'll find the attackpower and return it? I more or less want the opposite, I want to accrue a lot of values across a lot of arbitrary files quickly without a lot of get and set statements. Reference to a function? I don't understand your terminology. Sorry.[/QUOTE] Something like [code]class Player { public PlayerStatistics playerStats; } class PlayerStatistics { private int strength; private int magic; public void SetStat(string statistic, int value) { if(statistic == "strength") strength = value; else if(statistic == "magic") magic = value; } public void GetStat(string statistic) { ... } }[/code] basically
[QUOTE=Rayjingstorm;35545140]I may be wrong but won't [php] artistsInfo.indexOf(",", i); [/php] return a negative number if it finds nothing? I.E. You need to check if indexOf is negative (you are at the last substring) before you call substring or it will spit out an error (you cant start at a negative index within a string)[/QUOTE] Yeah, but I'm pretty sure it's only -1 that's returned so I don't see how I'm getting -203, although my notes on indexOf only state that it returns -1 for the one parameter methods and not the two parameter methods, hm.
I'm making an OpenGL GLUT bomberman game, and I have no idea how I should go about making the explosion for the bombs. Anyone got any ideas or pointers?
[QUOTE=G-Strogg;35551690]I'm making an OpenGL GLUT bomberman game, and I have no idea how I should go about making the explosion for the bombs. Anyone got any ideas or pointers?[/QUOTE] Draw a sprite on top of the bomb, then remove the bomb entity entirely?
I fixed the cube's drawing, it was an index problem, but now I have a problem with the UV coords, this is how I create everything: [cpp]g_vertex_buffer_data[0] = -0.5f; g_vertex_buffer_data[1] = 0.5f; g_vertex_buffer_data[2] = -0.5f; g_vertex_buffer_data[3] = 0.5f; g_vertex_buffer_data[4] = 0.5f; g_vertex_buffer_data[5] = -0.5f; g_vertex_buffer_data[6] = 0.5f; g_vertex_buffer_data[7] = -0.5f; g_vertex_buffer_data[8] = -0.5f; g_vertex_buffer_data[9] = -0.5f; g_vertex_buffer_data[10] = -0.5f; g_vertex_buffer_data[11] = -0.5f; g_vertex_buffer_data[12] = -0.5f; g_vertex_buffer_data[13] = 0.5f; g_vertex_buffer_data[14] = 0.5f; g_vertex_buffer_data[15] = 0.5f; g_vertex_buffer_data[16] = 0.5f; g_vertex_buffer_data[17] = 0.5f; g_vertex_buffer_data[18] = 0.5f; g_vertex_buffer_data[19] = -0.5f; g_vertex_buffer_data[20] = 0.5f; g_vertex_buffer_data[21] = -0.5f; g_vertex_buffer_data[22] = -0.5f; g_vertex_buffer_data[23] = 0.5f; // Generate 1 buffer, put the resulting identifier in vertexbuffer glGenBuffers(1, &vertexbuffer); // The following commands will talk about our 'vertexbuffer' buffer glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); // Give our vertices to OpenGL. glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); for(int i = 0; i < 6; i++) { int ii = i * 8; uv_data[0 + ii] = 0.0f; uv_data[1 + ii] = 0.0f; uv_data[2 + ii] = 1.0f; uv_data[3 + ii] = 0.0f; uv_data[4 + ii] = 1.0f; uv_data[5 + ii] = 1.0f; uv_data[6 + ii] = 1.0f; uv_data[7 + ii] = 1.0f; } // Generate 1 buffer, put the resulting identifier in vertexbuffer glGenBuffers(1, &uvbuffer); // The following commands will talk about our 'vertexbuffer' buffer glBindBuffer(GL_ARRAY_BUFFER, uvbuffer); // Give our vertices to OpenGL. glBufferData(GL_ARRAY_BUFFER, sizeof(uv_data), uv_data, GL_STATIC_DRAW); ///Back of the cube indices.push_back( 1 ); indices.push_back( 2 ); indices.push_back( 0 ); indices.push_back( 0 ); indices.push_back( 2 ); indices.push_back( 3 ); ///Left side indices.push_back( 0 ); indices.push_back( 3 ); indices.push_back( 4 ); indices.push_back( 4 ); indices.push_back( 3 ); indices.push_back( 7 ); ///Front indices.push_back( 4 ); indices.push_back( 7 ); indices.push_back( 5 ); indices.push_back( 5 ); indices.push_back( 7 ); indices.push_back( 6 ); ///Right indices.push_back( 5 ); indices.push_back( 6 ); indices.push_back( 2 ); indices.push_back( 1 ); indices.push_back( 5 ); indices.push_back( 2 ); ///Top indices.push_back( 4 ); indices.push_back( 5 ); indices.push_back( 0 ); indices.push_back( 0 ); indices.push_back( 5 ); indices.push_back( 1 ); ///Bottom indices.push_back( 6 ); indices.push_back( 7 ); indices.push_back( 3 ); indices.push_back( 2 ); indices.push_back( 6 ); indices.push_back( 3 ); // fill "indices" as needed // Generate a buffer for the indices glGenBuffers(1, &elementbuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), &indices[0], GL_STATIC_DRAW); texture.loadFromFile("img.png"); texture.setSmooth(true);[/cpp] And this is what gets drawn: [IMG]http://i.imgur.com/MAuuA.png[/IMG]
Guys I tried to install SFML following [URL="http://www.sfml-dev.org/tutorials/1.6/start-vc.php"]this tutorial[/URL] but when I try to compile the example I get this error: [code] 1>------ Build started: Project: Test, Configuration: Debug Win32 ------ 1> Test.cpp 1>c:\users\xxxxxxxxx\documents\visual studio 2010\projects\test\test\test.cpp(1): warning C4627: '#include <SFML/System.hpp>': skipped when looking for precompiled header use 1> Add directive to 'StdAfx.h' or rebuild precompiled header 1>c:\users\xxxxxxxxx\documents\visual studio 2010\projects\test\test\test.cpp(2): warning C4627: '#include <iostream>': skipped when looking for precompiled header use 1> Add directive to 'StdAfx.h' or rebuild precompiled header 1>c:\users\xxxxxxxxx\documents\visual studio 2010\projects\test\test\test.cpp(7): error C2653: 'sf' : is not a class or namespace name 1>c:\users\xxxxxxxxx\documents\visual studio 2010\projects\test\test\test.cpp(7): error C2065: 'Clock' : undeclared identifier 1>c:\users\xxxxxxxxx\documents\visual studio 2010\projects\test\test\test.cpp(7): error C2146: syntax error : missing ';' before identifier 'Clock' 1>c:\users\xxxxxxxxx\documents\visual studio 2010\projects\test\test\test.cpp(7): error C2065: 'Clock' : undeclared identifier 1>c:\users\xxxxxxxxx\documents\visual studio 2010\projects\test\test\test.cpp(8): error C2065: 'Clock' : undeclared identifier 1>c:\users\xxxxxxxxx\documents\visual studio 2010\projects\test\test\test.cpp(8): error C2228: left of '.GetElapsedTime' must have class/struct/union 1> type is ''unknown-type'' 1>c:\users\xxxxxxxxx\documents\visual studio 2010\projects\test\test\test.cpp(8): fatal error C1903: unable to recover from previous error(s); stopping compilation ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== [/code]
[QUOTE=mechanarchy;35547506]I'm pretty sure you've already called ilInit() - you'd be segfaulting on that line if you hadn't. So that's not an issue. Have you called ilGenImages and ilBindImage first? If not, that's your problem. Otherwise, it's probably unable to find the image - most likely due to a working directory issue. You can check this by putting in the full path of the image, until you work out what the filename should be or the best way to run the program to avoid working directory path issues. eg for reference here is how I use DevIL [cpp] ilGenImages(1, &ImageHandle_); ilBindImage(ImageHandle_); bool ret = ilLoadImage(Filename_.c_str()); if(ilGetError() == IL_COULD_NOT_OPEN_FILE) { printf("\nError loading texture file \"%s\"\n\n", Filename_.c_str()); ilDeleteImages(1, &ImageHandle_); ImageHandle_ = 0; return false; } else if(ret == false) { // Some other error occurred. We could poll the whole IL stack, but // I can't be assed writing code for all that. ilDeleteImages(1, &ImageHandle_); ImageHandle_ = 0; return false; } // Ensure image is in RGBA format. ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); return true; [/cpp][/QUOTE] Yep, I've got ilInit and imagename-generation and binding seems to work fine. I tried putting logo.png in the same folder as the project-file, and it seems to load fine now. I'm not getting an error. I guess the working-directory is set to the same folder as the projectfile while running in debug-mode in MSVC+ 2010. By the way, what's the story behind "ilConvertImage()"?
is there any way to pass a bool to the vertex shader? ATM im doing: [cpp] glUniform1f(DrawLinesID, (float)prog->drawLines); ///in frag shader: varying float drawLines; uniform float DrawLines; void main(){ drawLines = DrawLines; ... } // in vertex varying float drawLines; void main(){ if(drawLines == 1.0f) gl_FragColor = vec4(1,1,1,1); else if(drawLines == 0.0f) gl_FragColor = texture2D( myTexture, uv ).rgba; }[/cpp]
[QUOTE=Richy19;35554828]is there any way to pass a bool to the vertex shader? ATM im doing: [cpp] glUniform1f(DrawLinesID, (float)prog->drawLines); ///in frag shader: varying float drawLines; uniform float DrawLines; void main(){ drawLines = DrawLines; ... } // in vertex varying float drawLines; void main(){ if(drawLines == 1.0f) gl_FragColor = vec4(1,1,1,1); else if(drawLines == 0.0f) gl_FragColor = texture2D( myTexture, uv ).rgba; }[/cpp][/QUOTE] I'd use an integer instead of a float.
How would I get this: [cpp]double realpow(double x, double y) { double z,err,a,b; z = 1; while(x != 1 && y > 0) { if(y >= 1) { y = y-1; z = z*x; } else { /* fractional power (0 < y < 1): pow(x,y)=pow(sqrt(x),2y) * e.g. pow(4,0.5) = pow(2,1) = 2 * so first approximate the square root of x */ a = (1+x)/2; do { b = a; a = (a+x/a)/2; if(a > b) err = (a-b)/a; else err = (b-a)/a; // keep doing this until error (a.k.a. 'epsilon') is low enough } while(err > 0.0000001); // set x = sqrt(x), y = 2y and loop x = a; y = 2*y; } } return z; } // main method for testing void main(int argc, char** argv) { printf("%g\t%g\t%g\n",2.0,3.0,realpow(2.0,3.0)); printf("%g\t%g\t%g\n",4.0,1.5,realpow(4.0,1.5)); printf("%g\t%g\t%g\n",25.0,0.5,realpow(25.0,0.5)); printf("%g\t%g\t%g\n",81.0,0.25,realpow(81.0,0.25)); printf("%g\t%g\t%g\n",10.0,1.2,realpow(10.0,1.2)); }[/cpp] And get it working in Assembly language (Mip64) Really need help with this guys if anybody could help me it would be super sweet
[QUOTE=ROBO_DONUT;35554938]I'd use an integer instead of a float.[/QUOTE] problem is, if i use an int I get something along the lines of, variying variables must be of base type float [editline]13th April 2012[/editline] [QUOTE=ROBO_DONUT;35554938]I'd use an integer instead of a float.[/QUOTE] Did this and it works perfect: [cpp] varying float drawLines; void main(){ if( int(drawLines+0.5f) == 1) gl_FragColor = vec4(1,1,1,1); else if(drawLines == 0.0f) gl_FragColor = texture2D( myTexture, uv ).rgba; }[/cpp]
Just get rid of the 'varying' attribute. You can use uniforms directly in the fragment shader.
[QUOTE=Bazkip;35550591]Yeah, but I'm pretty sure it's only -1 that's returned so I don't see how I'm getting -203, although my notes on indexOf only state that it returns -1 for the one parameter methods and not the two parameter methods, hm.[/QUOTE] Its the only thing I see, and so long as it is negative it is inconsequential what it actually returns. If you check for it being negative do you get the same error?
I'm having some trouble with making an Open File Dialog in Windows. I've used: "GetOpenFileName", but that just returns "" and never pops up a box to ask for what file. Is it because I'm using a Console application instead of a Window application? Code: [cpp] std::string CreateOpenFileDialog(const char *filter = "All Files (*.*)\0*.*\0") { OPENFILENAMEA ofn; char fileName[MAX_PATH]; memset(&ofn, 0, sizeof(OPENFILENAMEA)); ofn.lStructSize = sizeof(OPENFILENAMEA); ofn.hwndOwner = NULL; ofn.lpstrFilter = filter; ofn.lpstrFile = fileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = ""; std::string fileNameStr; if(GetOpenFileNameA(&ofn)) fileNameStr = fileName; return fileNameStr; } [/cpp] Accepting solutions that involve Boost, because frankly, I don't really want to write file-dialog stuff myself.
Does anyone have a good tutorial series for C#?
[QUOTE=Larikang;35459244]There's something about derived classes in C++ that I'm not understanding. [cpp] #include <iostream> using namespace std; class Base { public: Base() { cerr << "Created base " << this << endl; } virtual ~Base() { cerr << "Destroyed base " << this << endl; } }; class Derived : public Base { public: Derived() { cerr << "Created derived " << this << endl; } Derived(const Base & b) { cerr << "Copied derived " << this << endl; } ~Derived() { cerr << "Destroyed derived " << this << endl; } }; int main() { Derived x; Derived y (x); return EXIT_SUCCESS; }[/cpp] Displays [code] Created base 0x1234 Created derived 0x1234 Destroyed derived 0x5678 Destroyed base 0x5678 Destroyed derived 0x1234 Destroyed base 0x1234 [/code] That is to say, Derived y (x) calls only the implicit Base copy constructor, skipping the one I defined entirely. Why is that? I figured it would interpret x as a Base, and find the matching constructor declaration, but instead it seems to interpret both x and y as Base. The reason I'm trying to do this is because I want several classes all deriving from the same abstract base class, but all able to be constructed using any of the others - without needing to code a specific constructor for each class. Using the clone pattern works, but that's almost as tedious because then I need to define a clone method for every derived class.[/QUOTE] Okay, I need to revive this. shill's solution of doing [cpp]Derived y ((Base)x);[/cpp] works for the example I posted, but not if Base is an abstract class. The compiler tries to allocate a Base object. Is there a way to treat the Derived object like a Base just for the purpose of passing it to the function?
Still using OpenGL and DevIL here, and I'm having trouble getting my quad to display my texture. I've gotten the texture to load fine, and the quad is showed, but it's completely red. I do have the texture bound, and I am giving it texture coordinates. I also have it set to repeat on edges, so it should show even if the coordinates were to be off. I've gotten a clue that it might be because I'm handling the shaders wrongly? I haven't been able to find any info about a shader-type that supports textures. Anyone care to help? Here's the draw-code itself: [cpp]// Handle the textured quad glBegin(GL_QUADS); glTexCoord2d(0.0,0.0); glVertex2d(-0.5,-0.5); glTexCoord2d(1.0,0.0); glVertex2d(0.5,-0.5); glTexCoord2d(1.0,1.0); glVertex2d(0.5,0.5); glTexCoord2d(0.0,1.0); glVertex2d(-0.5,0.5); glEnd();[/cpp] And here's the full application on pastebin: [url]http://pastebin.com/Qft1w0iD[/url] All the initialization of the texture happens in the "main()" function, and the rendering happens in the "RenderScene()" function.
You need to set GL_TEXTURE_(MIN/MAG)_FILTER to GL_NEAREST or GL_LINEAR if you don't have mipmaps
Sorry, you need to Log In to post a reply to this thread.