Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

116 Neutral

About aGuyWhoSucksAtOpenGL

  • Rank
  1. aGuyWhoSucksAtOpenGL

    Move glVertex Position

    Ah, perfect, that did the trick! I really can't thank you enough, I've spent far too long trying to figure all of this out. Let me know if you have a bitcoin address and I'll be sure to send a few mbtc your way, thanks again!
  2. aGuyWhoSucksAtOpenGL

    Move glVertex Position

    Ah, I see your point, however in the above, defining x and y is just resetting the image dimensions, so that being called again shouldn't be a problem. As for the initPos variables, I'm redefining positionX beforehand in order to move the position of the object, so that being called again is needed in order to redraw the shape in the appropriate position, right? And to answer your question, I'm coding it for Mac at the moment- no real reason for it, just fancied doing it on such- I'll probably end up porting it to the iPhone eventually anyway.   I've been playing around with my code for the past few hours and I've somewhat solved my problem, well, kind of.   I was originally going to write a big explanation about what's wrong and what's working but I've recorded a video instead (linked here and below). Basically the NSRect function only gets called once initially, and every time the window size is repositioned thereafter. Placing the following code in the NSRect function works fine when resizing the window, but it's not exactly the way I want to move the image! haha if (myInt < 1){ self.player = [[GLSprite alloc] initWithFile:@"tmp" fileFormat:@"png"]; [self.player render]; myInt++; } else{ self.player.positionX += 10; [self.player render]; } Alas, thinking I was close to figuring it out, I put the code into a separate function and called it at set intervals with an NSTimer. It didn't work. What instead happens is the image is drawn and drawn whilst being continuously repositioned- it's what happens in the second part of the video. Any ideas why it's doing that? Thanks again for the help though   Video:  (computer was lagging hard from quicktime, sorry for the slow recording)   Edit: Here's another example of the problem from using an NSTimer to call the above code (I've added mousetracking rather than an increasing integer):    Edit 2: A timer probably isn't the best way to invoke the image re-position, but I can't think of a better solution. Any ideas?  
  3. aGuyWhoSucksAtOpenGL

    Move glVertex Position

    Thanks Marc, great tips there, I really appreciate it. I'll have a 'lil look into GLEssentials and see what I can do.     As for the code, I didn't explain myself very well, sorry. My problem doesn't lie in positioning the vertex as such but instead being able to reposition it after it's initially displayed, e.g// Everytime a number increments, or the mouse moves in a certain direction, the glVertex changes position and is re-rendered on the screen. The positioning I can handle, but I don't know how to constantly keep the triangle strip updating to adjust to the new coordinates- at the moment I can render the image, but for example, if I then altered moveVertex, it'd have no effect on the image's position. Any ideas how to fix this and keep the strip+texture updating?   In the mean time, I plan to go look through the example code from GLEssentials, thanks again for the help
  4. aGuyWhoSucksAtOpenGL

    Move glVertex Position

    Thanks for the link Marc, I've had a little browse through some of their OpenGL projects and they seem to rely quite heavily on using GLKit for a lot of their code. Not a bad thing, just I'm not too familiar with it. I'll perhaps play around with it later on today, in the meantime if anyone is able to chip in, it'd be much appreciated. My problem isn't really language specific, I'm just trying to figure out a way to move the vertexes whilst the programs running, be that in c, c++ or obj-c.
  5. aGuyWhoSucksAtOpenGL

    Move glVertex Position

    Hi,   I usually only turn to forums when I'm completely and utterly stuck on a problem, and guess what? I'm completely and utterly stuck! Each time I think I've figured out a way for my code to work, I rush to my keyboard and my ideas are quickly shot down.   My question is, how do I actively re-position a trianglestrip as the program is running?     I'll be honest, I have pretty much no clue as to how to do this without reloading both the image and texture. The code I was previously using, used a timer that refreshed the screen every 0.05s and each time it did so, it was re-allocating and re-drawing my texture. Not the most efficient way to move an image.    This is the code I'm currently using in order to display the image and set it's position (coding in Obj-C): -(void)addSprite{ // This code works btw, image is drawn on screen and positioned accordingly self.player = [[GLSprite alloc] initWithFile:@"logo2" fileFormat:@"png"]; self.player.positionX = 100; [self.player render]; }   This is the code I'm trying to use to loop the render function in order to redraw it (am I even correct in doing this?). This code doesn't work at all (image doesn't show up) but it's a rough attempt at what I'm trying to do. [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval) 0.05 target:self selector:@selector(update) userInfo:nil repeats:YES]; -(void)update{ myInt += 1; if (myInt < 2) { // Calls alloc once self.player = [[GLSprite alloc] initWithFile:@"logo2" fileFormat:@"png"]; NSLog(@"ALLOC"); } // Render, render, render that image self.player.positionX += 10; // Increments x coordinate every 0.05s (will eventually revert xPos to be dependant on mouse) [self.player render]; NSLog(@"RENDER"); }   And finally, here's the implementation of the functions from the above code:  -(id)initWithFile:(NSString *)imageName fileFormat: (NSString *) format{ if ((self = [super init])) { [GLSprite getWindowSize]; NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:  [NSNumber numberWithBool:YES],  GLKTextureLoaderOriginBottomLeft,  nil]; NSString *imageURL, *dirImage; imageURL = [NSString stringWithFormat:@"images/%@", imageName]; dirImage = [[NSBundle mainBundle] pathForResource:imageURL ofType:format]; NSError *error; self.texture = [GLKTextureLoader textureWithContentsOfFile:dirImage options:options error:&error]; if (error) { NSLog(@"Error loading texture from image: %@",error); } } return self; }  -(void)render{ x = (self.texture.width / window.x); y = (self.texture.height / window.y); self.initPositionX = (self.positionX / window.x) * 2; self.initPositionY = (self.positionY / window.y) * 2; xCoord[0] = 0 - x; yCoord[0] = 0 - y; xCoord[1] = 0 + x; yCoord[1] = 0 - y; xCoord[2] = 0 - x; yCoord[2] = 0 + y; xCoord[3] = 0 + x; yCoord[3] = 0 + y; NSLog(@"Render: %f", self.initPositionX); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_TRIANGLE_STRIP); glTexCoord2d(0.0, 0.0); glVertex2d(xCoord[0] + self.initPositionX, yCoord[0] + self.initPositionY); glTexCoord2d(1.0, 0.0); glVertex2d(xCoord[1] + self.initPositionX, yCoord[1] + self.initPositionY); glTexCoord2d(0.0, 1.0); glVertex2d(xCoord[2] + self.initPositionX, yCoord[2] + self.initPositionY); glTexCoord2d(1.0, 1.0); glVertex2d(xCoord[3] + self.initPositionX, yCoord[3] + self.initPositionY); glEnd(); }   I'm most likely completely wrong in what I'm trying to achieve so any help would be great, thanks!
  6. aGuyWhoSucksAtOpenGL

    Problem with texture mapping

    Ah, that might be the problem, thanks, I'll give it a go. Will update in a few mins! Also, thanks for the tips Dave, much appreciated.   Edit: Yup, that did the trick, I can't thank you enough BornToCode! The funny thing is that I already had that line in my code, I'd just commented it out at some point- I'm an idiot. Thanks again!
  7. aGuyWhoSucksAtOpenGL

    OpenGL Problem with texture mapping

    Hi all,    Today was my first step into the mighty land of OpenGL and so the first task I set myself- after playing around with shapes and colours- was to display an image on screen. So far, I've been attempting to texturise a quad for the past 5/6 hours with not much luck, well, none at all really. The rest of the code seems to work fine, I just can't get the texture to show. As a side note, my eyes are beginning to glaze over right now, so if anything I say doesn't make sense, just skip a few lines and see if that does the trick.   What choo doing? I'm using SOIL in my code, so the problem may lie with that if the rest of the code seems fine. If you lovely people could check my code for mistakes, I'd greatly appreciate it, thanks! As I said, I'm still a noob and so I can't figure out where I've gone wrong. As for my code, I'm writing this on a mac, so some functions are written in obj-c.   Where yo' code at? -(void) loadTextures{ GLuint textures[1]; glGenTextures( 1, textures ); int width, height; width = 128; height = 256; unsigned char *image; glBindTexture( GL_TEXTURE_2D, textures[0] ); image = SOIL_load_image( "logo.png", &width, &height, 0, SOIL_LOAD_RGB ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image ); SOIL_free_image_data( image ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 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(); } - (void)drawRect:(NSRect)dirtyRect { glClearColor(0, 104.0/255.0, 55.0/255.0, 1.0); // rgba ; Red, Green, Blue, Alpha (transparency) glClear(GL_COLOR_BUFFER_BIT); // if no buffer is present, glclear has no effect. glclear clears buffers to preset values. MyOpenGLView *GLView = [[MyOpenGLView alloc] init]; [GLView loadTextures]; glFlush(); // forces execution of GL commands. }     I'm off to sleep now, this code -albeit small- has worn me out. Any responses would be fantastic, I've looked over and over my code, checked with what seems like a million other pieces of source code and yet I still can't figure out the issue, obviously there is, as the texture isn't loading! If I don't respond within a couple of minutes, odds are I'm asleep, but any responses would be much appreciated and I'll be sure to reply back in around 6 hours time.   Thanks!   Edit: Here's what I'm getting at the moment: http://i.imgur.com/JOFaYG6.png
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!