Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#ActualaGuyWhoSucksAtOpenGL

Posted 13 June 2013 - 01:25 PM

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!

#5aGuyWhoSucksAtOpenGL

Posted 13 June 2013 - 01:22 PM

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) {
self.player = [[GLSprite alloc] initWithFile:@"logo2" fileFormat:@"png"];
NSLog(@"ALLOC"); // Calls alloc once
}
self.player.positionX += 10; // Increments x coordinate every 0.05s (will eventually revert xPos to be dependant on mouse) 
[self.player render];
NSLog(@"RENDER"); // Render, render, render that image
}
 
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!

#4aGuyWhoSucksAtOpenGL

Posted 13 June 2013 - 01:21 PM

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{
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) {
self.player = [[GLSprite alloc] initWithFile:@"logo2" fileFormat:@"png"];
NSLog(@"ALLOC"); // Calls alloc once
}
self.player.positionX += 10; // Increments x coordinate every 0.05s (will eventually revert xPos to be dependant on mouse) 
[self.player render];
NSLog(@"RENDER"); // Render, render, render that image
}
 
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!

#3aGuyWhoSucksAtOpenGL

Posted 13 June 2013 - 01:21 PM

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{
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) {
self.player = [[GLSprite alloc] initWithFile:@"logo2" fileFormat:@"png"];
NSLog(@"ALLOC"); // Calls alloc once
}
self.player.positionX += 10; // Increments x coordinate every 0.05s (will eventually revert xPos to be dependant on mouse) 
[self.player render];
NSLog(@"RENDER"); // Render, render, render that image
}
 
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!

#2aGuyWhoSucksAtOpenGL

Posted 13 June 2013 - 01:18 PM

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{
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) {
self.player = [[GLSprite alloc] initWithFile:@"logo2" fileFormat:@"png"];
NSLog(@"ALLOC"); // Calls alloc once
}
self.player.positionX += 10;
[self.player render];
NSLog(@"RENDER"); // Render, render, render that image
}
 
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!

#1aGuyWhoSucksAtOpenGL

Posted 13 June 2013 - 01:17 PM

Hi,
 
I usually only turn to forums when I'm completely and utterly stuck on a problem, and so, 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:
-(void)addSprite{
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) {
self.player = [[GLSprite alloc] initWithFile:@"logo2" fileFormat:@"png"];
NSLog(@"ALLOC"); // Calls alloc once
}
self.player.positionX += 10;
[self.player render];
NSLog(@"RENDER"); // Render, render, render that image
}
 
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!

PARTNERS